1

Since the increment operator ++ is not supported in python, why doesn't it cause an error when prefixing a variable. Example:

i = 3
++i

prints 3 on the interactive console. Why is that?

Tarik
  • 10,810
  • 2
  • 26
  • 40

2 Answers2

5

Take a look - it's just a sign:

>>> i = 3
>>> +i
3
>>> ++i
3
>>> +++i
3
>>> -i
-3
>>> --i
3
>>> ---i
-3
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
3

Python treats ++i as +(+i), that would compile fine, and print the same value as of i.

Rohit Jain
  • 209,639
  • 45
  • 409
  • 525