Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyClassObject:
- def __init__(self):
- # this function must be in any class and will run when instantiated
- self.var = 100
- def print_value(self):
- # all class methods (functions) must have their first argument be 'self'
- print self.var
- def add_10(self):
- self.var = self.var + 10
- a = MyClassObject()
- a.print_value() # expect 100. this will call the print_value method of the class
- a.add_10()
- a.print_value() # expect 110
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement