标签:print rom names default mes list ace cti port
# 命名元组
from collections import namedtuple
subscriber = namedtuple(typename=‘Subscriber‘, field_names=[‘name‘, ‘age‘])
sub = subscriber(‘lisi‘, 10)
print(sub)
print(sub.name)
print(sub.age)
print(len(sub))
name, age = sub
print(name)
print(age)
list1 = [(‘a‘, 1), (‘b‘, 2), (‘c‘, 3)]
for rec in list1:
s = subscriber(*rec)
print(s.name, ‘==‘, s.age)
default_sub = subscriber(‘佚名‘, 0)
list2 = [{‘name‘: ‘lisi‘}, {‘name‘: ‘wangwu‘, ‘age‘: 12}, {‘age‘: 11}]
for i in list2:
s = default_sub._replace(**i)
print(s)
# Subscriber(name=‘lisi‘, age=0)
# Subscriber(name=‘wangwu‘, age=12)
# Subscriber(name=‘佚名‘, age=11)
标签:print rom names default mes list ace cti port
原文地址:https://www.cnblogs.com/fly-book/p/13396683.html