ITPub博客

首页 > IT职业 > IT职场 > python面向对象

python面向对象

IT职场 作者:klayman 时间:2021-09-09 09:20:19 0 删除 编辑

class Person(object):

name = ""

# age = ""
# height = 0
def 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 

per1 = Person("tom",12,168)
print(per1.name)
per1.chi("apple")
per1.SetMoney(4)
print(per1)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3974/viewspace-2802379/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2026-01-07

  • 博文量
    76
  • 访问量
    6108