新聞中心
方法說明

創(chuàng)新互聯(lián)是專業(yè)的徐州網(wǎng)站建設(shè)公司,徐州接單;提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行徐州網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
1、__or__和__ror__魔法方法對應(yīng)于|操作符,__or__表示對象在操作符的左邊,__ror__表示對象在操作符的右邊。實(shí)現(xiàn)是根據(jù)左邊的操作數(shù)量生成新的字典,然后將右邊的操作數(shù)量更新到新的字典中,然后返回新的字典。
2、__ior__魔法方法對應(yīng)|=操作符,右邊的操作數(shù)量可以自己更新。
實(shí)例
def __or__(self, other): if not isinstance(other, DICT): return NotImplemented new = dict(self) new.update(other) return new def __ror__(self, other): if not isinstance(other, dict): return NotImplemented new = dict(other) new.update(self) return new def __ior__(self, other): dict.update(self, other) return self
以上就是python dict實(shí)現(xiàn)的魔法方法,希望對大家有所幫助。更多編程基礎(chǔ)知識(shí)學(xué)習(xí):python學(xué)習(xí)網(wǎng)
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
分享文章:創(chuàng)新互聯(lián)Python教程:pythondict實(shí)現(xiàn)的魔法方法
網(wǎng)站網(wǎng)址:http://fisionsoft.com.cn/article/ccdchos.html


咨詢
建站咨詢
