How to count by twos with Python's 'range'

前端 未结 3 731
眼角桃花
眼角桃花 2021-02-19 00:35

So imagine I want to go over a loop from 0 to 100, but skipping the odd numbers (so going \"two by two\").

for x in range(0,100):
    if x%2 == 0:
        print          


        
3条回答
  •  半阙折子戏
    2021-02-19 00:54

    for i in range(0, 100, 2):
        print i
    

    If you are using an IDE, it tells you syntax:

    min, max, step(optional)

提交回复
热议问题