Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16743

What is the point of getters/setters in OOP python? [duplicate]

$
0
0

I know that getters and setters are important in java as you usually have private attributes, but I cannot find any use in making them in Python.

If we take for exemple the User class given below:

class User:    def __init__(self, username):        self.logined = True        self.username = username    def logout(self):        self.logined = False        self.username = None    def login(self, username):        self.logined = True        self.username = username    def is_logined(self):        return self.logined

And then creating an instance of User in a main.py

user = User("Pixa253lulu")user.logout()#Way 1print(user.is_logined())#Way 2print(user.logined)

Both would return True in that case, and seems to work just fine in any situation.So is there any practical use like in Java, or is using those just commiting to OOP?


Viewing all articles
Browse latest Browse all 16743

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>