源代碼下載:下載地址在這裏
# 034 class Person: def __init__(self, name): self.name = name # 這一句中第一個name是類中包含的域,第二個name是傳進來的參數 # end of def def sayHello(self): print 'Hello!' # end of def # end of class p = Person('Ning') print p.name p.sayHello()
output:
Ning Hello!
例1: # _018 # This is a module (if write Chinese in a module, there will be a error) def func1(): print 'This is f
源代碼下載:下載地址在這裏 # 039 while True: try: x = int(raw_input('Input a number:')) y = int(raw_input('In
源代碼下載:下載地址在這裏 # 035 class Person: population = 0 #這個變量是屬於整個類的 def __init__(self, name): self.name =