Skip to content

Instantly share code, notes, and snippets.

@arjunprakash027
Created October 11, 2023 11:28
Show Gist options
  • Save arjunprakash027/066ef38673a8408e95697173f6bbe5e3 to your computer and use it in GitHub Desktop.
Save arjunprakash027/066ef38673a8408e95697173f6bbe5e3 to your computer and use it in GitHub Desktop.

Revisions

  1. arjunprakash027 revised this gist Oct 11, 2023. No changes.
  2. arjunprakash027 created this gist Oct 11, 2023.
    40 changes: 40 additions & 0 deletions access_modifiers_py.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    class all_modify:

    #declaring public,proteced and private
    var1,_var2,__var3 = None,None,None

    def __init__(self,var1,var2,var3):
    self.var1 = var1
    self._var2 = var2
    self.__var3 = var3

    def disPub(self): #public method
    print("public",self.var1)

    def _disProc(self): #protected mthd- accessed from the derived class
    print("procted",self._var2)

    def __disPri(self): #private mthd- only be accessed from inside the class
    print("private",self.__var3)

    def DisPriMthd(self):
    self.__disPri()


    class sub(all_modify):

    def __init__(self,var1,var2,var3):
    all_modify.__init__(self,var1,var2,var3)

    def DisProcMthd(self):
    self._disProc()


    obj = sub(1,2,3)
    obj.disPub()
    obj.DisPriMthd()
    obj.DisProcMthd()

    print(obj.var1)
    print(obj._var2)
    print(obj.__var3)