Python class简介2

Contributor:知乎:三生万物【标签:老朽意识】 Type:English Date time:2020-04-29 13:22:20 Favorite:7 Score:0
返回上页 Report
请选择举报理由:




Collection Modify the typo
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.
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
Hot degree:
Difficulty:
quality:
Description: the system according to the heat, the difficulty, the quality of automatic certification, the certification of the article will be involved in typing!

This paper typing ranking TOP20

登录后可见