Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Created September 23, 2013 16:41
Show Gist options
  • Save wehappyfew/6673338 to your computer and use it in GitHub Desktop.
Save wehappyfew/6673338 to your computer and use it in GitHub Desktop.
codecademy python class exmaple
class Fruit(object):
"""A class that makes various tasty fruits."""
def __init__(self, name, color, flavor, poisonous):
self.name = name
self.color = color
self.flavor = flavor
self.poisonous = poisonous
def description(self):
print "I'm a %s %s and I taste %s." % (self.color, self.name, self.flavor)
def is_edible(self):
if not self.poisonous:
print "Yep! I'm edible."
else:
print "Don't eat me! I am super poisonous."
lemon = Fruit("lemon", "yellow", "sour", False)
lemon.description()
lemon.is_edible()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment