Demonstrates private variables and methods : Private : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Private »

 

Demonstrates private variables and methods


class MyClass(object):
    def __init__(self, name, mood):
        print "A new MyClass has been born!"
        self.name = name            # public attribute
        self.__mood = mood          # private attribute

    def talk(self):
        print "nI'm", self.name
        print "Right now I feel", self.__mood, "n"

    def __private_method(self):
        print "This is a private method."

    def public_method(self):
        print "This is a public method."
        self.__private_method()

crit = MyClass(name = "Jack", mood = "happy")
crit.talk()
crit.public_method()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Private