面向对象
''' name="元昊" gender="木" type="藏獒" dog1={ "name":"元昊", "gender":"mu", "type":"藏獒" } dog2={ "name":"元ng", "gender":"mu", "type":"111" } person1={ "name":"元sir", "gender":"mu", "type":"人" } def jiao(dog): print("一条狗[%s],嗡嗡嗡" %dog["name"]) def chi_shi(dog): print("一条狗[%s],吃屎" %dog["type"]) jiao(dog1) chi_shi(dog2) jiao(person1) ''' # def dog(naem,gender,type): # # def jiao(dog): # print("一条狗[%s],嗡嗡嗡" % dog["name"]) # # def chi_shi(dog): # print("一条狗[%s],吃屎" % dog["type"]) # # dog1 = { # "name": naem, # "gender": gender, # "type": type, # "jiao":jiao, # "chi_shi":chi_shi, # } # return dog1 # # # d1=dog() #主函数换了参数 # # print(d1) # # d1["chi_shi"](d1) # d1=dog("元昊","mu","中华田园犬") # d2=dog("alex","mu","中犬") # d1["chi_shi"](d1) # d2["chi_shi"](d2) #这就是面向对象 def dog(naem,gender,type): def jiao(dog): print("一条狗[%s],嗡嗡嗡" % dog["name"]) def chi_shi(dog): print("一条狗[%s],吃屎" % dog["type"]) def inin(name,gender,type): dog1 = { "name": naem, "gender": gender, "type": type, "jiao":jiao, "chi_shi":chi_shi, } return dog1 res=inin(naem,gender,type) return res d1=dog("元昊","mu","中华田园犬") d2=dog("alex","mu","中犬") d1["chi_shi"](d1) d2["chi_shi"](d2)