The Python class uses a

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.