Python class简介2

贡献者:知乎:三生万物【标签:老朽意识】 类别:英文 时间:2020-04-29 13:22:20 收藏数:7 评分:0
返回上页 举报此文章
请选择举报理由:




收藏到我的文章 改错字
Therefore,imaging you want to create a human, which has all character as real human,and this
type of object has eyes,mouth,ear,and it can sing,jump,rap.
Apparently,you could not do something like:
[1] 猴子 = Human() #当然变量不能是中文名,这里为了方便理解
[2] print(human.upper()) #人这个类型还能大写?系统会报错"AttributeError"
You may find in the line 1 I use human = Human(),so what is Human()? Ok,now we could speak more
frankly,that the Human actually is what we called class in python, actually it the type you
defined.So how can we define the human type?
[1]class Human:
[2] def __init__(self):
[3] self.eye = 两只
[4] self.mouth = 一只
[5] def sing(self,分贝,音色):
[6] '''此处开始以该对象的分贝和音高唱歌'''
Now we have defined a Human type(class),for the variable 猴子,we assign the Human()--one of the
instance of Human to it.(就是把人这个类实例化出一个给猴子这个变量,然后猴子就有了人这个类的一切属性和
方法).
See you next time,we would talk about self in the next text.
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:
文章难度:
文章质量:
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!

本文打字排名TOP20

登录后可见