Define function to change member data : Class Method : Class PYTHON examples


PYTHON examples » Class » Class Method »

 

Define function to change member data


Define function to change member data
 


class NextClass:                            # define class
    def printer(self, text):                # define method
        self.message = text                 # change instance
        print self.message                  # access instance

x = NextClass()                             # make instance

x.printer('instance call')              # call its method

print x.message                               # instance changed

NextClass.printer(x, 'class call')      # direct class call

print x.message                               # instance changed again


           
         
  



Leave a Comment / Note


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


PYTHON examples

 Navioo Class
» Class Method