Python class 3

貢獻者:知乎:三生万物【标签:老朽意识】 類別:英文 時間:2020-06-13 21:36:57 收藏數:9 評分:0
返回上页 舉報此文章
请选择举报理由:




收藏到我的文章 改錯字
(我会分开两部分讨论实例这个概念)
Last time we have attach to some superficial knowledge of Object-oriented Programming in python,
that we defined a class and some attribute inside. As what we discussed in previous snippet, python
has some built-in data type and some of them have it's own method--for example, "I am a string".
upper() are used to converting this string into uppercase, that is it would be "I AM A STRING".And
we could also find that we could not apply it to int type like 5.upper() would be treated as
exception which clash with rule of python.
But last time we remain a conundrum and let us do a quick recap:
Class Human:
def __init__(self,name):
self.name = name
self.run = "False"
def running(self):
self.run = "True"
human1 = Human("Peter")
print(human1.run)#Would print out "False"
human1.running()
print(human1.run)#Would print out "True"
Through the code above,we define a class Human, and two method inside, one is "__init__",another
is "running",while both of them has a "self" as the first parameter.Why we do that?
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章熱度:
文章難度:
文章質量:
說明:系統根據文章的熱度、難度、質量自動認證,已認證的文章將參與打字排名!

本文打字排名TOP20

登录后可见