40 Access modifiers in python

 '''

1. All name variables and methods are public by default in Python


2. Protected variable we can define By prefixing the name of your variable or 

method with a single underscore.

 Protected mean you’re telling others “don’t touch this, unless you’re a subclass”


3. private variable we can define By prefixing 

the name of your variable with a double underscore, By declaring your data member private you mean, 

that nobody should be able to access it from outside the class.


'''

class One():

    name   = ' public '     # public

    _name  = ' protect '    # protect

    __name = ' Pravate '    # pravate


    def sum(self):

        #self.__sub()

        print(' \n Public ' )


    def _add(self):

        print(' \n Protect ' )


    def __sub(self):

        print(' \n Pravate ')


ins = One()

ins.sum()


#print(' \n ', ins.__name)







Comments

Popular posts from this blog

1 PYTHON PROGRAMMING

4 Tuple data types

2 String data types