摘要:本篇Pyhton语言教程将为大家讲解Pyhton编程的知识点,看完这篇文章会让你对Python编程的知识点有更加清晰的理解和运用。
本篇Pyhton语言教程将为大家讲解Pyhton编程的知识点,看完这篇文章会让你对Python编程的知识点有更加清晰的理解和运用。
class Person():
def __init__(self, name):
self.name = name
def eat(self, food): # 属于类对象
print('吃%s...' % food)
p = Person('wang')
print(p.name)
p.eat('蛋糕')
print(Person.__dict__)
print(p.__dict__)
1 wang2 吃蛋糕...3 {'__module__': '__main__', '__init__': <function Person.__init__ at 0x00000000023338C8>, 'eat': <function Person.eat at 0x0000000002333730>, '__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__': <attribute '__weakref__' of 'Person' objects>, '__doc__': None}4 {'name': 'wang'}
动态方法添加
class Person():
pass
def eat(food):
print('吃%s...' % food)
p = Person()
p.name = 'wang'
p.eat = eat # 属于实例对象,与上面的是有区别的
print(p.name)
p.eat('蛋糕')
print(Person.__dict__)
print(p.__dict__)
1 wang2 吃蛋糕...3 {'__module__': '__main__', '__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__': <attribute '__weakref__' of 'Person' objects>, '__doc__': None}4 {'name': 'wang', 'eat': <function eat at 0x00000000027E90D0>}
以上,关于Pyhton的全部内容讲解完毕啦,欢迎大家继续关注!更多关于Python的干货请关注职坐标Python频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号