Python i++ increment

To increment integer variable in python use:

i += 1

Example:

i = 11
i += 1
print(i)

Will print 12

Python i++ in loop

In loops it is recommended to use range instead of incrementing:

for i in range(5):
   print(i)

Will print 0 1 2 3 4

If you need a custom starting point useL

for i in range(2, 5):
   print(i)

Will print 2 3 4.

#python #increment
menu 3
Bruce Hardy profile picture
Nov 01, 2020
by Bruce Hardy

Best related

Other by Bruce Hardy