编程语言
首页 > 编程语言> > python开发基础(四)面向对象--实例化

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='饺子')

 

标签:name,chinese,面向对象,python,self,habit,--,number1,print
来源: https://www.cnblogs.com/longloved/p/15086760.html