Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created Jul 14, 2020
Embed
What would you like to do?
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