Advertisement
Peaser

toggleable boolean class example

Sep 13th, 2014
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. class Toggleable(object):
  2.     def __init__(self, boolean):
  3.         self.boolean = boolean
  4.  
  5.     def __repr__(self):
  6.         return str(self.boolean)
  7.  
  8.     def toggle(self):
  9.         if self.boolean == True:
  10.             self.boolean = False
  11.         elif self.boolean == False:
  12.             self.boolean = True
  13.  
  14. def main():
  15.     a = Toggleable(True)
  16.     print a #true
  17.     a.toggle()
  18.     print a #false
  19.     a.toggle()
  20.     print a #true
  21.  
  22. if __name__ == '__main__':
  23.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement