python开发基础(四)面向对象--实例化

# 实例化
class Chinese:

    def __init__(self, chinese_name, chinese_age, chinese_gender):
        self.chinese_name = chinese_name
        self.chinese_age = chinese_age
        self.chinese_gender = chinese_gender

    # 函数属性
    def habit(self):
        print('%s like money' % self.chinese_name)

    def other_habit(self):
        print('%s has other habit' % self.chinese_name)

    def eat_foot(self, foot):
        print('%s正在吃%s' % (self.chinese_name, foot))


# 方法调用

s_number1 = Chinese('jack', 18, 'male')
# print(s_number1.chinese_name)  # print(s_number1.__dict__['chinese_name'])

s_number1.habit()
s_number1.other_habit()
s_number1.eat_foot(foot='饺子')

 

上一篇:CSDN,Chinese Software Develpoer Network,意想作文


下一篇:算法刷题的基础(一)——必会的算法基础知识