标签:调用 on() 参数 bsp pytho author class utf-8 int
#-*- coding:utf-8 -*-
__author__ = "MuT6 Sch01aR"
class Person():
def __init__(self,name,money = 100):
self.name = name
self.money = money
def talk(self):
print("%s is talking to the shop." % self.name)
def buy(self, thing):
print("%s has %s$ and buy a %s" % (self.name,self.money, thing))
p1 = Person("Jack") #实例化一个对象
p1.talk() #调用Person里的talk函数
p1.buy("meat")
def __init__(self) 为构造函数,给实例化的类传参数,self为实例化的对象赋予的变量,相当于例子中的p1
标签:调用 on() 参数 bsp pytho author class utf-8 int
原文地址:http://www.cnblogs.com/sch01ar/p/7769046.html