Tags
python
Asked 3 years ago
5 Aug 2021
Views 1584
Oma

Oma posted

What does i += 1 mean in Python ?

What does i += 1 mean in Python ?
iPhone-coder

iPhone-coder
answered Aug 8 '21 00:00

i+1 it means it increment i's value by 1

suppose i=0 and than if we put i=i+1 than i become 1
see the following code with while loop with i+1

i=0
while(i<=10):
	print(i)
	i=i+1;

it will print

0
1
2
3
4
5
6
7
8
9
10


so its simple plus arithmetic operator

it works the same with i-1, it does subtract by one
Rasi

Rasi
answered Aug 8 '21 00:00

i+1 work same as i++ in other language like PHP .

Python do not have i++
Post Answer