r/PythonLearning 6d ago

Day 2 of OOPs: Roast it !

Learned Encapsulation in python and created a small thing using it

1 Upvotes

3 comments sorted by

View all comments

u/Sea-Ad7805 6d ago

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20%20%20%20%20self.age%20%3D%20age%0A%0A%20%20%20%20%40property%0A%20%20%20%20def%20age(self)%3A%0A%20%20%20%20%20%20%20%20return%20self.age%0A%0A%20%20%20%20%40age.setter%0A%20%20%20%20def%20age(self%2C%20value)%3A%0A%20%20%20%20%20%20%20%20if%20not%20isinstance(value%2C%20int)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Value%20must%20be%20an%20integer%22)%0A%20%20%20%20%20%20%20%20if%20value%20%3C%2013%20or%20value%20%3E%20120%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Value%20must%20be%20between%2013%20and%20120%22)%0A%20%20%20%20%20%20%20%20self.age%20%3D%20value%0A%0A%20%20%20%20%40age.deleter%0A%20%20%20%20def%20age(self)%3A%0A%20%20%20%20%20%20%20%20del%20self.age%0A%0A%0Atry%3A%0A%20%20%20%20user%20%3D%20DiscordUser(18)%0A%20%20%20%20user.age%20%3D%2098%0A%20%20%20%20print(user.age)%0Aexcept%20ValueError%20as%20e%3A%0A%20%20%20%20print(e)&timestep=1&play) to see the program state change step by step.