Created
June 30, 2011 09:08
-
-
Save KyeRussell/1055899 to your computer and use it in GitHub Desktop.
Python OOP Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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