Python Object-oriented

Source: Internet
Author: User
class Person (object):

Name = ""

# age = ""# height = 0def run(self):    print("pao")def chi(self,food):    print("%s吃%s"%(self.name, food))#构造def __init__(self, name, age, height):    self.name = name    self.age = age    self.height = height    self.__money = 5000 #访问限制def SetMoney(self, num):    if num < 10000:        self.__money = 5000    else:        self.__money = num#重写def __str__(self):    return  "name:%s age:%d money: %d"%(self.name, self.age, self.__money)#析构def __del__(self):    print("对象释放")

Per1 = Person ("Tom", 12,168)
Print (Per1.name)
Per1.chi ("Apple")
Per1. Setmoney (4)
Print (Per1)

Python Object-oriented

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.