Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # local_vs_global.py
- class Car(object):
- __maxspeed = 0
- __name = ""
- def __init__(self):
- self.__maxspeed = 250
- self.__name = "Supercar"
- def drive(self):
- print 'global/hwy driving: maxspeed ' + str(self.__maxspeed)
- def change_maxspeed(self, limit):
- self.__maxspeed = limit
- redcar = Car()
- redcar.drive()
- redcar.__maxspeed = 80 # will not change variable because its private
- redcar.drive()
- print 'local driving:', redcar.__maxspeed # local
- redcar.change_maxspeed(40)
- redcar.drive()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement