定义一个函数只给了函数一个名称,指定了函数里包含的参数,和代码块结构。
这个函数的基本结构完成以后,你可以通过另一个函数调用执行,也可以直接从Python提示符执行。
class Chinese:
minzu='汉族'
def __init__(self,name,age,gender):
self.mingzi=name
self.nianjing=age
self.xingbie=gender
# print('我结束啦')
def notgood(self):
print('%s 乱扔垃圾的' %self.mingzi)
def verygood(self):
print(self)
print('%s 和谐相处' %self.mingzi)
def eat_food(self,food):
print('%s 正在吃%s' %(self.mingzi,food))
p1=Chinese('元',18,'female')
p1.notgood()
p1.eat_food('apple')