Skip to content

Instantly share code, notes, and snippets.

@KyeRussell
Created June 30, 2011 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyeRussell/1055899 to your computer and use it in GitHub Desktop.
Save KyeRussell/1055899 to your computer and use it in GitHub Desktop.
Python OOP Example
def main():
class Avatar (object):
def __init__(self, name, category):
self.name = name
self.cat = category
self.health = 100
self.magic = 25
def stats (self):
print("---[ Avatar Stats ]---")
print("Name:\t\t", self.name)
print("Category:\t", self.cat)
print("Health:\t\t", self.health)
print("Magic:\t\t", self.magic)
class Category (object):
def __init__(self, name):
self.name = name
self.desc = ''
def stats (self):
print("---[ Category Stats ]---")
print("Name:\t\t", self.name)
print("Description:\t", self.desc)
def __str__(self):
return self.name
ctgWizard = Category('Wizard')
ctgWizard.desc = 'An awesome wizard.'
John = Avatar('JohnSmith123', ctgWizard)
John.stats()
John.cat.stats()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment