7_17 面向对象
ef dog(name,gender,type):
# 狗的动作
def jiao(dog):
print('一条狗[%s],汪汪汪' % dog['name'])
def chi_shi(dog):
print('一条[%s] 正在吃屎' % dog['type'])
def init(name,gender,type):#初始化的方法
dog1 = {
'name':name,
'gender': gender,
'type': type,
'jiao':jiao,
'chi_shi':chi_shi,
}
return dog1
return init(name,gender,type)
d1=dog('元昊','母','中华田园犬')
d2=dog('alex','母','藏敖')
print(d1)
print(d2)
d1['jiao'](d1)
d2['chi_shi'](d2)
{'name': '元昊', 'gender': '母', 'type': '中华田园犬', 'jiao': <function dog.<locals>.jiao at 0x005D5270>, 'chi_shi': <function dog.<locals>.chi_shi at 0x005D5228>}
{'name': 'alex', 'gender': '母', 'type': '藏敖', 'jiao': <function dog.<locals>.jiao at 0x005D51E0>, 'chi_shi': <function dog.<locals>.chi_shi at 0x005D5108>}
一条狗[元昊],汪汪汪
一条[藏敖] 正在吃屎