Using an index to get an item, Python

前端 未结 5 1315
轮回少年
轮回少年 2020-11-30 10:23

I have a tuple in python (\'A\',\'B\',\'C\',\'D\',\'E\'), how do I get which item is under a particular index number?

Example: Say it was given 0, it would return A

5条回答
  •  旧时难觅i
    2020-11-30 10:46

    You can use _ _getitem__(key) function.

    >>> iterable = ('A', 'B', 'C', 'D', 'E')
    >>> key = 4
    >>> iterable.__getitem__(key)
    'E'
    

提交回复
热议问题