close

for Loop Increment by 2 in Python

Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about for Loop Increment by 2 in Python. so without wasting time lets learn about of this.

for Loop Increment by 2 in Python

  1. How to Increment by 2 in for Loop in Python

    to Increment by 2 in for Loop in Python Use range() By using range() you can for Loop Increment by 2 in Python. Lets learn about of this by given below example: for x in range(1, 13, 2): print(x) Output :
    1 3 5 7 9 11

  2. for Loop Increment by 2 in Python

    to Increment by 2 in for Loop in Python Use slicing method By using slicing method you can for Loop Increment by 2 in Python. Lets learn about of this by given below example: mylist = [1,2,3,4,5,6,7,8] for x in mylist[1::2]: print (x) Output : 2 4 6 8

Method 1: Use range()

By using range() you can for Loop Increment. Lets learn about of this by given below example:

for x in range(1, 13, 2):
  print(x)

Output :

1
3
5
7
9
11

Method 2: Use slicing method

By using slicing method you can for Loop Increment by 2. Lets learn about of this by given below example:

mylist = [1,2,3,4,5,6,7,8]
for x in mylist[1::2]:
    print (x)

Output :

2
4
6
8

Conclusion

It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?

Also, Read

Leave a Comment