What are classes and instances

Source: Internet
Author: User
Defines a people class in fact self, is the instance itself! When you instantiate it, Python automatically passes the instance itself through the self parameter.

class people (object):

def __init__(self,name): #构造函数 构造方法==初始化方法    self.name=name #这是此类的成员属性def saysome(self): #类的方法    print("what are you doing now ?",self.name)def eat(self,food,many):    print("%s say:the %s is very nice!%s"%(self.name,food,many))

P1=people (' Wang Yu ') #实例化后的对象叫 example!!
P2=people (' Ning Cheng ')

P1.saysome () #执行
P2.saysome ()
P1.eat (' root ', ' att ') '

What are classes and instances

Related Article

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.