Property Methods
property.setter()
Replace or supply the accessor used for assignment to a managed attribute. A setter normally accepts the instance and the new value; its return value is ignored during assignment. The method returns a new property descriptor; the original is unchanged. Rebind it to the class attribute (or use the decorator form with the same attribute name). In local CPython 3.13.5, passing None retains the existing accessor; construct a new property explicitly with a missing accessor to omit it. Missing accessors cause AttributeError when the corresponding operation is attempted.
Formal Syntax & Structure
python syntaxpython
descriptor.setter(fset, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| fset | Callable | None | Replacement accessor; None retains the existing accessor in CPython 3.13.5. |
Return Value
property
New descriptor with the selected accessor replaced.
Working Example
Example Snippetpython
def read(self): return self._valuedef write(self, value): self._value = valuedef erase(self): del self._valueoriginal = property(read, None, erase)updated = original.setter(write)class Item: value = updateditem = Item()item._value = 4item.value = 7print(item.value)print(original.fset is None, updated is original)