__setattr__

Dunder MethodPython 2.0+Advanced

Called on every attribute assignment

Quick Info

Documentation
Official Docs
Python Version
2.0+

Learn by Difficulty

Quick Example

python
class Example:
    def __setattr__(self):
        return "Example __setattr__"

obj = Example()
print(obj)

__setattr__ called on every attribute assignment. Implementing it lets you customize how Python interacts with your objects.

Try in Playground

Tags

oopmagic-methodprotocolcore