Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 14, 2020 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/0531276d7a60453fa9afef5d0575dd40 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/0531276d7a60453fa9afef5d0575dd40 to your computer and use it in GitHub Desktop.
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