对象的初始状态(构造函数)
生活随笔
收集整理的這篇文章主要介紹了
对象的初始状态(构造函数)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
class Person(object):# name = ""# age =0# height = 0# weight = 0def run(self):print("run")def eat(self,food):print("eat"+food)def __init__(self,name,age,height,weight):# print(name,age,weight,height)print("這里是init")self.name = nameself.height = heightself.age =ageself.weight = weightpass'''構(gòu)造函數(shù):__init__() 在使用類創(chuàng)建對象的時候自動調(diào)用注意:如果不顯示的寫出構(gòu)造函數(shù),默認(rèn)會自動添加一個空的函數(shù)
'''
per = Person("韓梅梅",20,170,55)print(per.name,per.weight)per2 = Person("lilei",21,180,90)print(per2.name,per2.weight)
?
總結(jié)
以上是生活随笔為你收集整理的对象的初始状态(构造函数)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php生成excel带图片格式,php导
- 下一篇: Dependency Walker