1

既然python中不支持自增运算符++,为什么在给变量加前缀的时候不会报错。例子:

i = 3
++i

在交互式控制台上打印 3。这是为什么?

4

2 回答 2

5

Take a look - it's just a sign:

>>> i = 3
>>> +i
3
>>> ++i
3
>>> +++i
3
>>> -i
-3
>>> --i
3
>>> ---i
-3
于 2013-08-29T09:06:33.120 回答
3

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

于 2013-08-29T09:07:37.500 回答