Python class 3

Contributor:知乎:三生万物【标签:老朽意识】 Type:English Date time:2020-06-13 21:36:57 Favorite:9 Score:0
返回上页 Report
请选择举报理由:




Collection Modify the typo
(我会分开两部分讨论实例这个概念)
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?
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
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