日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python学习——Day5

發(fā)布時間:2023/12/20 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python学习——Day5 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

5.1__init__

#__init__()可以在類里面初始化 class shemale_cai:def __init__(self):self.gender='女'self.age=1def print_info(self):print(f'蔡徐坤是一名籃球巨星,性別 {self.gender} 年齡 {self.age}') caixukun=shemale_cai() caixukun.print_info()

5.2__init__帶參數(shù)

class television():def __init__(self,width,height):self.width = widthself.height = heightdef print_info(self):print(f'電視機的寬度為{self.width}')print(f'電視機的高度為{self.height}') sony=television(30,20) sony.print_info()

5.3__str__()

class television():def __init__(self,width,height):self.width = widthself.height = heightdef print_info(self):print(f'電視機的寬度為{self.width}')print(f'電視機的高度為{self.height}')def __str__(self):return("這是索尼電視機的相關屬性")#print(sony)時不輸出內(nèi)存,輸出解釋說明文字 sony=television(30,20) sony.print_info() print(sony)

5.4__del__() 刪除

class television():def __init__(self,width,height):self.width = widthself.height = heightdef print_info(self):print(f'電視機的寬度為{self.width}')print(f'電視機的高度為{self.height}')def __del__(self):print('對象已經(jīng)刪除')#系統(tǒng)自動調(diào)用 sony=television(30,20) sony.print_info()

5.5 面向對象之繼承

#父類 class A(object):def __init__(self):self.num=1def info__print(self):print(self.num) #子類 class B(A):pass result=B() result.info__print()

5.6 單繼承

class teacher(object):def __init__(self):self.subject='數(shù)學成績'def study_math(self):print(f'好好學習取得好的{self.subject}') class student(teacher):pass xxx=student() print(xxx) xxx.study_math()

5.7 多繼承

class math_teacher(object):def __init__(self):self.subject='數(shù)學成績'def study_math(self):print(f'好好學習取得好的{self.subject}') class English_teacher(object):def __init__(self):self.subject='英語成績'def study_English(self):print(f'好好學習取得好的{self.subject}') class student(English_teacher,math_teacher):pass xxx=student() print(xxx) xxx.study_math() xxx.study_English()#一個類擁有多個父類時,默認使用第一個父類的同名屬性和用法 #同樣如果子類里面也有和父類相同名字的屬性,優(yōu)先子類

總結

以上是生活随笔為你收集整理的python学习——Day5的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。