One, self meaning
#-*-Coding:utf-8-*-class person:def One (self,name,age):p rint "you name was%s and you are%s."% (name, age) p = pers On () #绑定实例p. One ("Du", 22)
Execution Result:
You name are Du and you are 22.
In fact, self can not be written as self, but must have a parameter such as
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/9C/AF/wKiom1l0qE6h4ZLDAAA_ZXxRC5M801.png-wh_500x0-wm_ 3-wmp_4-s_2561148615.png "title=" 1.png "alt=" Wkiom1l0qe6h4zldaaa_zxxrc5m801.png-wh_50 "/>
For more information, refer to the blog: http://www.cnblogs.com/jessonluo/p/4717140.html
Two, __init__ initialization.
#-*-Coding:utf-8-*-class person:def __init__ (self,sex): Self.sex = sexdef One (self,name,age):p rint "You name is%s and You are%s and sex is%s "% (name, age, self.sex) p = person (" Boy ") #绑定实例p. One (" Du ", 22)
Execution Result:
You name are Du and you are age are and sex is a boy
It's actually equivalent to a variable sex in a class. than the function freshman level. The following procedure is the same as the result of the above execution.
#-*-coding:utf-8-*-class person:sex = "Boy" def __init__ (self,sex): #self. Sex = sexpassdef One (self,name,age):p rint "You Name is%s and you are%s and sex is%s "percent (name, age, self.sex) p = person (" Boy ") #绑定实例p. One (" Du ", 22)
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9C/B0/wKiom1l0rM7wxVsHAAQF1aT1ixQ739.png "title=" Enjoy. png "alt=" Wkiom1l0rm7wxvshaaqf1at1ixq739.png "/>
This article is from the "Tiandaochouqin" blog, make sure to keep this source http://tdcqvip.blog.51cto.com/12995943/1950270
The Python class uses a