當前位置:成語大全網 - 書法字典 - Python的enumerate()函數

Python的enumerate()函數

在python中,叠代是獲取元素本身,而不是元素索引,那麽如果想獲取壹個有序集的元素索引呢?

方法是使用enumerate()函數:

例如['A ',' B ',' C ',' D'],輸出結果為[(0,' A '),(1,' B '),(2,' C ',(3,' d')]