Access Modifiers: ================= In Java: ======== public ==> the public data, can allow to access in anywhere private ==> can allow to access within the class. protected ==> In Python: ========== public access modifiers ==> any normal data in class # Public Access Modifiers class publicAccessModifiers: # attributes which are public type a = 100 b = 12.234 c = 12-24j # public method def publicMethod(self): print("The First Attribute = ",self.a) print("The Second Attribute = ",self.b) print("The Third Attribute = ",self.c) print("The Class Variable1 = ",a) print("The Class variable2 = ",b) print("The Class variable3 = ",c) pma = publicAccessModifiers() pma.publicMethod() print(pma.a) print(pma.b) print(pma.c) private access modifiers ==> __ (variable should be prefixed) # Private Access Modifiers class privateAccessModifiers: # public data a = 10 b = 20 # private data __p = 123 __q = 321 print(__p,__q) def __privateMethod(self): # access the public data print("Public data1 = ",self.a) print("Public data2 = ",self.b) # access the private data print("Private data1 = ",self.__p) print("Private data2 = ",self.__q) def publicMethod(self): print("The Private data of the class are = ") print(self.__p) print(self.__q) obj = privateAccessModifiers() obj.publicMethod() # obj.__privateMethod() # print(obj.__p) protected access modifiers ==> _ (variable should be prefixed) # Protected Access Modifiers class protectedModifiers: _a = 1212 _b = "String" print("The Protected Data = ") print(_a) print(_b) def _met1(self): print("The Protected data = ") print(self._a) print(self._b) def __met2(self): print("The Protected Data = ") print(self._a) print(self._b) def met3(self): print("The Protected Data = ") print(self._a) print(self._b) self.__met2() obj = protectedModifiers() # obj._met1() obj.met3() print(obj._a) ========================================================== Instance Methods: ================= the methods which can define with "self" as parameter ==> are called as "instance methods". ==> Instance methods can always allowed to access with an object. # Instance Methods class Student: def __init__(self,sname, sroll, smarks): self.sname = sname self.sroll = sroll self.smarks = smarks def instance(self): print("The Student data = ") print("Name = ",self.sname) print("Roll = ",self.sroll) print("Marks = ",self.smarks) stu = Student("Ayan",12,78) stu.instance() # Student.instance(123) Instance Variables: =================== ==> the variables inside the instance method called as "Instance Variables". #Instance Variables class calculator: def addition(self): self.a = 100 self.b = 200 print("sum = ",self.a + self.b) def product(self): print("product = ",self.a * self.b) cal = calculator() cal.addition() cal.product() print(cal.a) print(cal.b) # print(calculator.a)