namedtuple
python APIs
byHAJUNHO12분전
from collections import namedtuple
# or
import collections
param4tuple = ['name', 'age', 'sex', 'address', 'phoneNumber']
personcardskim = namedtuple('whatever1', param4tuple, defaults=(None,) * len(param4tuple))
person001 = personcardskim('Eddie')
print('person001 =', person001)
personcardskim2 = namedtuple('whatever2', 'name age sex address phoneNumber')
person002 = personcardskim2('joe', '34', 'male', 'korea', '01022223333')
print('person002 =', person002)
difficultTuple = namedtuple('whatever3', ['name', 'age', 'sex'])
person003 = difficultTuple('helloman', '18', 'male')
print('person003 = ', person003)
importTuple = collections.namedtuple('whatever4', 'name age sex', defaults=(None,) * 3)
person004 = importTuple('haha')
print('person004 = ', person004)
person001.name
Out[3]: 'Eddie'
person002.name
Out[4]: 'joe'
person003.name
Out[5]: 'helloman'
person004.name
Out[6]: 'haha'
최근댓글