What are "named tuples" in Python?
Posted
by Denilson Sá
on Stack Overflow
See other posts from Stack Overflow
or by Denilson Sá
Published on 2010-06-03T23:50:16Z
Indexed on
2010/06/16
6:32 UTC
Read the original article
Hit count: 227
Reading the changes in Python 3.1, I found something... unexpected:
The sys.version_info tuple is now a named tuple:
I never heard about named tuples before, and I thought elements could either be indexed by numbers (like in tuples and lists) or by keys (like in dicts). I never expected they could be indexed both ways.
Thus, my questions are:
- What are named tuples?
- How to use them?
- Why/when should I use named tuples instead of normal tuples?
- Why/when should I use normal tuples instead of named tuples?
- Is there any kind of "named list" (a mutable version of the named tuple)?
© Stack Overflow or respective owner