for Loop Increment by 2 in Python

Hi guys. How are you all? I hope you all fine. Today in this tutorial we will learn about for Loop Increment by 2 in Python. We can increment a digit by 2 in python. And got the sequence of 2, 4, 6, 8, 10 etc. So here we will learn different methods to increment the digit by 2 in python. So here i am giving you some methods. I hope you guys like it learn by this method. So lets learn this:

for Loop Increment by 2 in Python

1. for Loop Increment by 2 in Python

to increment for loop by 2 in python just Use for loop and range(). Here we will use for loop with the range() function. Here we will use three parameters. parameters are : start, stop and step. start will increment all the numbers by 2 excepting tha last digit. So lets learn this by given below example. I hope this will help you.
`for i in range(0, 14, 2): print(i)` Output : `0 2 4 6 8 10 12`

2. How to increment for loop by 2 in python

to increment for loop by 2 in python just Use for loop and slicing. By using slicing method with for loop you can increment by 2. Here we will use slicing method which is represented by ” : ” It also have three parameters like start , end and step. Here i took 1 as a start parameter and step as 2 as like we want increment by 2. So lets learn this method by given below example. I hope this will help you and you like it. So lets learn this. `mylist = [1,2,3,4,5,6,7,8,9,10,12,14] for i in mylist[1::2]: print (i)` Output : `2 4 6 8 10 14`

Method 1: Use for loop and range()

Here we will use for loop with the range() function. Here we will use three parameters. parameters are : start, stop and step. start will increment all the numbers by 2 excepting tha last digit. So lets learn this by given below example. I hope this will help you.

``````for i in range(0, 14, 2):
print(i)``````

Output :

``````0
2
4
6
8
10
12``````

Method 2: Use for loop and slicing

By using slicing method with for loop you can increment by 2. Here we will use slicing method which is represented by ” : ” It also have three parameters like start , end and step. Here i took 1 as a start parameter and step as 2 as like we want increment by 2. So lets learn this method by given below example. I hope this will help you and you like it. So lets learn this.

``````mylist = [1,2,3,4,5,6,7,8,9,10,12,14]
for i in mylist[1::2]:
print (i)``````

Output :

``````2
4
6
8
10
14``````

Method 3: Use while loop

You can also increment the digit by 2 in python by using while loop. First of all make your list and take i = 0 and then use just while loop with it and here you have to take i += 2 because you want to increment by 2 So lets learn this by given below example. I hope you guys like it.

``````mylist = [1,2,3,4,5,6,7,8,9,10,12,14]
i = 0
while(i < len(mylist)):
print(mylist[i], end = " ")
i += 2``````

Output :

``1 3 5 7 9 12``

Conclusion

Hope all 6 Method Are Useful For You. Comment Below Which Method You Used To Convert String To Datetime In Python. Thank You.