Advertisement
codemonkey

class_test.py

Oct 17th, 2011
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # Human class
  2. class human:
  3.     age = 0
  4.     height = 0
  5.     affiliation = 'noob'
  6.    
  7.     # Constructor
  8.     def __init__(self, age, height, affiliation):
  9.         self.age = age
  10.         self.height = height
  11.         self.affiliation = affiliation
  12.    
  13.     # Magic function for string output
  14.     def __str__(self):
  15.         return "<human: age=%d; height=%d; affiliation=%s>" \
  16.             % (self.age, self.height, self.affiliation)
  17.  
  18. # Make some humans in a dictionary
  19. humans = {
  20.     'steffen': human(19, 50, 'noob'),
  21.     'tony': human(20, 88, 'noob'),
  22.     'tomsan': human(19, 87, 'pro')
  23. }
  24.  
  25. # Loop through the humans and print them
  26. for h in humans:
  27.     print humans[h]
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement