对象的初始状态(构造函数)
生活随笔
收集整理的這篇文章主要介紹了
对象的初始状态(构造函数)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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'''構造函數:__init__() 在使用類創建對象的時候自動調用注意:如果不顯示的寫出構造函數,默認會自動添加一個空的函數
'''
per = Person("韓梅梅",20,170,55)print(per.name,per.weight)per2 = Person("lilei",21,180,90)print(per2.name,per2.weight)
?
總結
以上是生活随笔為你收集整理的对象的初始状态(构造函数)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php生成excel带图片格式,php导
- 下一篇: Dependency Walker