返回列表 發帖

for 迴圈 (一)

#range(start,stop,step)
#range(1,6)->[1,2,3,4,5]


直向顯示第1名~第5名

  1. for i in range(1,6):
  2.     print("第",i,"名")
複製代碼

  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder Editor

  4. This is a temporary script file.
  5. """
  6. list1 =[0,1,2,3,4,"apple","忠",9,999]   


  7. for Martin in list1:
  8.     print(Martin,"嗨")
  9. #range(1,100)->[1,2,3,4,5]
  10. for i in range(1,6):
  11.     print(f"第{i}名")
  12. list2=[1,2,3,4,5]
  13. for i in list2:
  14.     print(f"第{i}名")
複製代碼

TOP

  1. for a in range(1,6):
  2.     print("第",a,"名")
複製代碼

TOP

  1. for i in range(1,6):
  2.     print("第",i,"名")
複製代碼

TOP

  1. list=[1,2,3,4,5]
  2. for a in list:
  3.     print(f"第{a}名")
  4.    
複製代碼

TOP

  1. for i in range(1,6):
  2.     print(f"第{i}名")
複製代碼

TOP

  1. list1=[0,1,2,3,4,"apple","忠",9,999]

  2. for kevin in list1:
  3.     print(kevin,"嗨")
  4.    
  5. #range(1,100)->[1,2,3,4,5]
  6. for i in range(1,6):
  7.     print(f"第{i}名")
  8. list2=[1,2,3,4,5]
  9. for i in list2:
  10.     print(f"第{i}名")
複製代碼

TOP

返回列表