python命名元組如何理解
說明
1、NamedTuples是屬於集合模組的輕量級、記憶體高效的物件型別。
2、這些是類似字典的構造,可以在其中透過索引、鍵名或 getattr()函式訪問屬性值。
例項
從輸入匯入 NamedTuple class Account(NamedTuple): name:str value: float Account(name='Naina',value=100)
輸出
帳戶(名稱='Naina',值=100.1) 從集合匯入 defaultdict 學費_餘額= defaultdict(lambda:200) 學費_存款 = [帳戶(姓名 =“奈娜”,價值=100), 帳戶(姓名 =“史蒂夫”,價值 = 300), 帳戶(姓名 =“本尼迪克特”,價值 = 200)] 在tuition_deposits 中的存款: tuition_balances[deposit.name]+=deposit.value print(dict(tuition_balances))
以上就是python命名元組的理解,希望對大家有所幫助。更多Python學習指路:
本文教程操作環境:windows7系統、Python 3.9.1,DELL G3電腦。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/506/viewspace-2828510/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Python奇技淫巧—[2]—使用元組代替字典,同時為元組元素命名,提高可讀性Python
- python元組如何打包和解包Python
- 資料型別· 第1篇《元組和列表的效能分析、命名元組》資料型別
- Python 元組Python
- python如何返回元組,列表或字典的?Python
- python如何訪問元組中的元素Python
- Python tuple(元組)Python
- python的元組Python
- Python元組tuplePython
- Python元組詳解Python
- python元組和列表Python
- Python基礎_元組Python
- 認識Python 元組Python
- 06_Python 元組Python
- python--元組tuplePython
- Python 建立元組tuplePython
- 理解 Python 位元組碼Python
- Python列表、元組、字典使用Python
- Python 基礎 3 - 元組Python
- Python的元組()與字典{}Python
- Python 學習之元組Python
- python元組的特點Python
- Python的元組()與字典 { }Python
- Python基礎(05):元組Python
- 初學Python(五)——元組Python
- python列表元組的操作Python
- Python的元組和列表Python
- python學習:元組tuplePython
- 理解Python中的元類Python
- 為元組中的每個元素命名,提高程式可讀性
- python元組與字典簡介Python
- python_列表——元組——字典——集合Python
- Python 學習之元組列表Python
- python list列表基礎(元組)Python
- Python之列表&元組小練Python
- python入門:元組和字典Python
- python基礎之元組,列表Python
- python list(列表)和tuple(元組)Python