-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

5
  • 2
    python won't support this feature. You could use i +=1 Commented Mar 2, 2015 at 10:29
  • 1
    "What have I done wrong": You have used ++ in a python program. Commented Mar 2, 2015 at 10:37
  • so I should be hanged???? Commented Mar 2, 2015 at 10:43
  • What do you mean by that? Commented Mar 2, 2015 at 10:48
  • or at least sent off to read the language documentation. Commented Mar 2, 2015 at 10:49

2 Answers 2

4

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

i += 1 
Sign up to request clarification or add additional context in comments.

3 Comments

i+=i+1 is not equal to i++
I have noticed, right after:) But thanks for reminding:)
Even i += 1 is not the same what you expected i++ to do. Integers are immutable in Python. With i += 1 you create a new integer behind the scenes.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.