-5

I cant use i++ in python. My code is

i=0
while i<10:
   print i
   i++

But it works fine if I replace i++ with i=i+1 it works. What have I done wrong

2 Answers2

4

There is no ++ operator in python. You must use

i += 1
Beri
  • 11,470
  • 4
  • 35
  • 57
4

It's just that i++ isn't supported in python. Replace that loop as follows:

i=0
while i<10:
   print i
   i += 1 # add 1 to i.

Or, even better (in case you are indeed using loops that way):

for i in range(0, 10):
    print i

Please take a look here for a list of all operators.

codingEnthusiast
  • 3,800
  • 2
  • 25
  • 37