面向对象

class Person:
    country = "China"

    def __init__(self, name, hp, aggr, sex):  # self 实际上是一个大字典
        self.name = name
        self.hp = hp
        self.aggr = aggr
        self.sex = sex

    def walk(self, n):
        print("%s走啊,走了%s步" % (self.name, n))


nxr = Person("nxr", 100, 1, "")
# nxr.age = 23
# nxr.name = "abc"
# print(nxr.name)
# nxr.walk(5)
# print(nxr.name)
# print(Person.__dict__["country"])
# print(nxr.__dict__["name"])
# nxr.__dict__["name"] = "二哥"
# print(nxr.__dict__)

 

posted @ 2019-02-15 15:44  飞蝎儿  阅读(101)  评论(0编辑  收藏  举报