Advertisement
codemonkey

class_test.py

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