I want to create a class in python that has setters for its attributes.
For example suppose we have a class named myClass
and it has x
attribute. I want to create it so that when someone changes x value, only two last digits of x (x % 100)
are saved.
using myClass in python shell:
>>> obj = myClass()
>>> obj.x = 352562
>>> obj.x
62
Can I define a setter that is called automatically when changing the value of x
?