新聞中心
使用說明

創(chuàng)新互聯(lián)是一家以網(wǎng)站設(shè)計建設(shè),成都微信小程序、網(wǎng)站開發(fā)設(shè)計,網(wǎng)絡(luò)軟件產(chǎn)品開發(fā),企業(yè)互聯(lián)網(wǎng)推廣服務(wù)為主的民營科技公司。主要業(yè)務(wù)涵蓋:為客戶提供網(wǎng)站策劃、網(wǎng)站設(shè)計、網(wǎng)站開發(fā)、域名注冊、網(wǎng)站優(yōu)化排名、買鏈接等服務(wù)領(lǐng)域。憑借建站老客戶口碑做市場,建設(shè)網(wǎng)站時,根據(jù)市場搜索規(guī)律和搜索引擎的排名收錄規(guī)律編程,全力為建站客戶設(shè)計制作排名好的網(wǎng)站,深受老客戶認(rèn)可和贊譽(yù)。
1、靜態(tài)方法取消了不需要的參數(shù)傳遞,能夠減少不必要的內(nèi)存占用和性能消耗。
2、類中定義了同名的靜態(tài)方法時,調(diào)用方法會優(yōu)先執(zhí)行最后定義的方法。
實(shí)例
class Date:
def __init__(self, year, month, day):
self.year = year
self.month = month
self.day = day
def __str__(self):
return ("{year}-{month}-{day}").format(year=self.year, month=self.month, day=self.day)
def yesterday(Date):
Date.day -= 1
@staticmethod # 用這個裝飾器表明是靜態(tài)方法,這個要注意。
def static(date_str):
year, month, day = tuple(date_str.split("-"))
return Date(int(year), int(month), int(day))
new_day=Date.static("2018-10-10") #由于靜態(tài)方法不屬于實(shí)例 所以調(diào)用的時候, 用類名.靜態(tài)方法,這個要注意
print(new_day)
#打印結(jié)果 正好是咱們的預(yù)期結(jié)果。
2018-10-10以上就是python靜態(tài)方法的使用注意點(diǎn),希望對大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
當(dāng)前題目:創(chuàng)新互聯(lián)Python教程:python靜態(tài)方法的使用注意點(diǎn)
鏈接地址:http://fisionsoft.com.cn/article/ccdesdi.html


咨詢
建站咨詢
