<abbr id="ciwa6"><option id="ciwa6"></option></abbr>
  • <sup id="ciwa6"><kbd id="ciwa6"></kbd></sup>
    <small id="ciwa6"></small>
  • 千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構(gòu)

    400-811-9990
    手機站
    千鋒教育

    千鋒學習站 | 隨時隨地免費學

    千鋒教育

    掃一掃進入千鋒手機站

    領(lǐng)取全套視頻
    千鋒教育

    關(guān)注千鋒學習站小程序
    隨時隨地免費學習課程

    上海
    • 北京
    • 鄭州
    • 武漢
    • 成都
    • 西安
    • 沈陽
    • 廣州
    • 南京
    • 深圳
    • 大連
    • 青島
    • 杭州
    • 重慶
    當前位置:成都千鋒IT培訓  >  技術(shù)干貨  >  python如何實例化一個對象

    python如何實例化一個對象

    來源:千鋒教育
    發(fā)布人:xqq
    時間: 2023-11-09 23:32:48

    python中同樣使用關(guān)鍵字class創(chuàng)建一個類,類名稱第一個字母大寫,可以帶括號也可以不帶括號;python中實例化類不需要使用關(guān)鍵字

    new(也沒有這個關(guān)鍵字),類的實例化類似函數(shù)調(diào)用方式;

    #coding:utf-8

    #創(chuàng)建一個類,類名稱第一個字母大寫,可以帶括號也可以不帶括號

    classStudent():

    student_count=0

    def__init__(self,name,salary):

    self.name=name

    self.age=salary

    Student.student_count+=1

    defdisplay_count(self):

    print('Totalstudent{}'.format(Student.student_count))

    defdisplay_student(self):

    print('Name:{},age:{}'.format(self.name,self.age))

    defget_class(self):

    ifself.age>=7andself.age<8:

    return1

    ifself.age>=8andself.age<9:

    return2

    ifself.age>=9andself.age<10:

    return3

    ifself.age>=10andself.age<11:

    return4

    else:

    return0

    創(chuàng)建類的對象(實例化類)

    python中實例化類不需要使用關(guān)鍵字new(也沒有這個關(guān)鍵字),類的實例化類似函數(shù)調(diào)用方式。

    student1=Student('cuiyongyuan',10)

    student2=Student('yuanli',10)

    student1.display_student()

    student2.display_student()

    student1_class=student1.get_class()

    以上內(nèi)容為大家介紹了python培訓之如何實例化一個對象,希望對大家有所幫助,如果想要了解更多Python相關(guān)知識,請關(guān)注IT培訓機構(gòu):千鋒教育。

    聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。

    猜你喜歡LIKE

    python delattr函數(shù)如何使用?

    2023-11-10

    python time.strptime的格式化

    2023-11-10

    pythonGIL在Python多線程的應(yīng)用

    2023-11-10

    最新文章NEW

    python中pdb模塊怎么用?

    2023-11-10

    Python如何截圖保存?

    2023-11-10

    python?中缺少module怎么辦?

    2023-11-10

    相關(guān)推薦HOT

    更多>>

    快速通道 更多>>

    最新開班信息 更多>>

    網(wǎng)友熱搜 更多>>