(‘jack‘,‘16‘,‘male‘,‘[email protected]‘)(‘eric‘,‘17‘,‘[email protected]‘)(‘xander‘,‘female‘,‘[email protected]‘)
方案一:
from enum import IntEnumname,AGE,SEX,EMAIL=range(4)s=(‘jim‘,‘[email protected]‘)# print(name) # 0class StudentEnum(IntEnum): name=0 AGE=1 SEX=2 EMAIL=3print(s[StudentEnum.name]) # jimprint(isinstance(StudentEnum.name,int)) # True
方案二:
from collections import namedtupleStudent=namedtuple(‘Student‘,[‘name‘,‘age‘,‘sex‘,‘email‘])s2=Student(‘jim‘,‘[email protected]‘)s3=Student(‘eric‘,‘[email protected]‘)print(s2) # Student(name=‘jim‘,age=‘16‘,sex=‘male‘,email=‘[email protected]‘)print(s3) # Student(name=‘eric‘,email=‘[email protected]‘)总结
以上是内存溢出为你收集整理的Python 提高元组的可读性全部内容,希望文章能够帮你解决Python 提高元组的可读性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)