如何定义常量
#全部大写用下划线连接
SCREEN_HEIGHT = 600
SCREEN_WIDTH = 800
SCREEN_SIZE = (SCREEN_WIDTH,SCREEN_HEIGHT)
ORIGINAL_CAPTION = "Super Mario Bros 1-1"
## COLORS ##
# R G B
GRAY = (100, 100, 100)
NAVYBLUE = ( 60, 60, 100)
如何定义类实例成员变量
#在__init__函数中定义
class Sound(object):
"""Handles all sound for the game"""
def __init__(self, overhead_info):
"""Initialize the class"""
self.sfx_dict = setup.SFX
self.music_dict = setup.MUSIC
self.overhead_info = overhead_info
self.game_info = overhead_info.game_info
self.set_music_mixer()
如何调用类实例方法
sound_obj = Sound()
sound.xxx()