Skip to main content

replace

Return a new object replacing specified fields with new values.

This is especially useful for immutable objects, like named tuples or frozen dataclasses.

def replace(
obj: object,
**changes: dict
) - > object

Return a new object replacing specified fields with new values. This is especially useful for immutable objects, like named tuples or frozen dataclasses.

Parameters

NameTypeDescription
objobjectThe object instance to be copied and modified.
**changesdictKeyword arguments representing the field names and their corresponding new values to be updated in the new object.

Returns

TypeDescription
objectA new instance of the same class with the updated field values applied.