-
-
Save IndhumathyChelliah/0531276d7a60453fa9afef5d0575dd40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student: | |
def __init__(self,name,rollno): | |
self.name=name | |
self.__rollno=rollno | |
def __repr__(self): | |
return "{},{}".format(self.name,self.rollno) | |
s=Student("Karthi",12) | |
print (s.name) | |
#Unable to access attributes having leading double underscore. | |
print (s.__rollno)#Output:AttributeError: 'Student' object has no attribute '__rollno' | |
#Name Mangling - have to use class extension with variable name | |
print (s._Student__rollno)#Output: 12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment