0

What this i++ and why basically we wrote this on loops?

please read the title😁 thx for the support guys

29th Nov 2016, 4:13 PM
Lidor Cohen
Lidor Cohen - avatar
4 Answers
+ 4
There is no ++ operand in python. Use i += 1 instead. It's the same as i = i+1. And you don't need this while looping, there are better ways in python: for elem in mylist: elem += 1 for index, value in enumerate(mylist): #if you need to operate with indexes mylist[index] = value + 1
29th Nov 2016, 4:29 PM
donkeyhot
donkeyhot - avatar
0
It is increment operation. By default it increments the value by 1. i++ if used in a function or print, it will print the value first and then set it to i+1. Whereas ++i means increase the value first then print it or use it or pass it. Warning python doesnt use this convention. Python equivalent is i+= 1
30th Nov 2016, 12:13 AM
Dinanath Basumatary
Dinanath Basumatary - avatar
0
ohh ok guys thank you so much 😊
30th Nov 2016, 1:10 AM
Lidor Cohen
Lidor Cohen - avatar
0
i++ is used for increment, Python doesn't use this kind of convention ( or should i say, Python has another way of doing this kind of operation ) Python's equivalent to i++ incrementation is i+=1
12th Dec 2016, 5:37 AM
Giam Paolo
Giam Paolo - avatar