Get the App
SLTechnology News&Howtos  ›  Development  › 

What is a python named tuple

Shulou Source: shulou.com Published: 2022-06-03 17:38:44 10月02日 Update

Editor to share with you what the python named tuple is, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Description

1. NamedTuples is a lightweight, memory-efficient object type that belongs to the collection module.

2. These are dictionary-like constructs in which attribute values can be accessed through indexes, key names, or getattr () functions.

Example

Import NamedTupleclass Account (NamedTuple): name:str value: float Account (name='Naina',value=100) from input

Output

Account (name = 'Naina', value = 100.1) import defaultdict tuition from the collection _ balance = defaultdict (lambda:200) tuition _ deposit = [account (name = "Nina", value = 100.1), account (name = "Steve", value = 100.1), account (name = "Benedict" Deposit in tuition_deposits: tuition_ balances [accounts. Name] + = deposit.valueprint (dict (tuition_balances)) these are all the contents of the article "what is a named tuple of python". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Account value name article content deposit tuition not much balance memory function name most dictionary instance object attribute more module knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft Huawei Docker Shulou Tech Info