阅读背景:

Python高级编程-如何为元祖中的每个元素命名,提高程序可读性?

来源:互联网 
NAME,AGE,SEX,EMAIL(4)
student= ('jim',16,'male','[email protected]')
#name
print student [NAME]
#age
if student[AGE]>16:
    pass
#sex
if student [SEX]=='male':
    pass



student= ('jim',16,'male','[email protected]')
from collections import namedtuple
student = namedtuple('student','name','age','sex','email')
s= student ('jim',16,'male','[email protected]')
s
s2=student(name='jim',age=16,sex='male',email='[email protected]')
s.name
'jim'
s.age
16NAME,AGE,SEX,EMAIL(4)
student= ('jim',16,'male'



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: