pyhton 为元组命名,提高可读性

# 1.使用命名变量获取index
name,age,sex,email = range(4)
student = ('jim',16,'male','[email protected]')
# student['name'] 'jim'

# 2.使用标准库collections.namedtuple

from collections import namedtuple
student = namedtuple('student',['name','age','sex','email'])

jim = student('jim','16','male','[email protected]')

# jim.name jim
# jim.age 16

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-06-09
猜你喜欢
  • 2022-02-10
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-12-05
相关资源
相似解决方案