Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python named tuples

from collections import namedtuple
A = namedtuple('A', 'a b c')
a = A(1,2,3)
a.b == a[1] # == 2
a == A(1,2,3) # is True
a[2] = 5 # TypeError: 'A' object does not support item assignment
len(a) # == 3
type(a) # <class '__main__.A'>
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #python #named #tuples
ADD COMMENT
Topic
Name
4+4 =