当前位置:   article > 正文

Python遍历list元素_python遍历list集合中的全部元素

python遍历list集合中的全部元素
  1. list1 = [1, 2, 3, 4, 5] # define list
  2. # After list1.append() operations
  3. print('without index')
  4. for value in list1:
  5. print(value, end=' ')
  6. print()
  7. print('with index ①')
  8. for index in range(len(list1)):
  9. print(f'list1[{index}] = {list1[index]}')
  10. print('with index ②')
  11. i = 0
  12. for value in list1:
  13. print(f'list1[{i}] = {value}')
  14. i += 1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/201936?site
推荐阅读
相关标签
  

闽ICP备14008679号