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()
'잡동사니' 카테고리의 다른 글
Codecademy - Python. class basic code( shopping cart ) (0) | 2015.10.30 |
---|---|
Codecademy - Python. battleship game (0) | 2015.10.18 |
[코드스터디] 5주차 (0) | 2015.06.25 |
[코드스터디] 4주차 (0) | 2015.06.25 |
[코드스터디] 3주차 (0) | 2015.06.25 |