예제 #1
0
Monster.weapon
# 'sword'
jubjub = Monster()
type(jubjub)
# <class 'monster.Monster'>
jubjub.hit_points
# 1
jubjub.hit_points = 5
jubjub.hit_points
# 5
jabberwock = Monster()
jabberwock.hit_points
# 1

# error because you arent calling it on a instance of a class
Monster.battlecry()
#Traceback (most recent call last):
#  File "<stdin>", line 1, in <module>
#TypeError: battlecry() missing 1 required positional argument: 'self'

jubjub = Monster()
jubjub.battlecry()
# 'ROAR'
jubjub.sound = "tweet"
jubjub.battlecry()
# 'TWEET'


class Store:
    open = 9
    close = 5
예제 #2
0
#! /usr/bin/python

from monster import Monster

scary = Monster()

scary.name = 'Bob'
scary.weapon = 'torch'
scary.color = 'black'


print scary.weapon
print scary.battlecry()

scary.sound = "Moo"

print scary.battlecry()
print scary.warning()