Copy Functions
copy.replace()
Create a new object with specified fields replaced, for named tuples, dataclass instances and objects implementing __replace__. Does not recursively copy unchanged fields.
Formal Syntax & Structure
python syntaxpython
copy.replace(obj, /, **changes)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| obj | object | Object to inspect or copy. |
| changes | object | Named replacement fields and their values. |
Return Value
object
The object result described above.
Working Example
Example Snippetpython
import copyfrom dataclasses import dataclass@dataclass(frozen=True)class Point: x:int y:intp=Point(2,3)print(copy.replace(p,y=8))