在python中,++x是正确的语法.“++x"是什么意思?意思? [英] in python, ++x is correct syntax. What does "++x" mean?

查看:72
本文介绍了在python中,++x是正确的语法.“++x"是什么意思?意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

可能的重复:
Python:自增和自减运算符的行为

<预><代码>>>>a=2>>>++a2>>>一个++回溯(文件<交互式输入>",第 1 行一个++^语法错误:无效语法>>>++a2

为什么 ++x 没问题?

(我问的是因为有人在工作中习惯性地写了++i,这并没有像(习惯性)预期的那样做,但也没有抛出错误,所以花了一些时间才找到错误.)

解决方案

表示+(+a),即与-(-a)的意思相反(虽然显然在这种情况下,结果是一样的!)

参见 http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex.

Possible Duplicate:
Python: Behaviour of increment and decrement operators

>>> a=2
>>> ++a
2
>>> a++
Traceback (  File "<interactive input>", line 1
    a++
      ^
SyntaxError: invalid syntax
>>> ++a
2

why ++x is OK?

(I'm asking since someone at work habitually wrote ++i, which didn't do as (habitually) expected, but didn't throw an error either, so it took some time to find the bug.)

解决方案

It means +(+a), i.e. opposite to the meaning of -(-a) (although obviously in this case, the result is the same!)

See http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex.

这篇关于在python中,++x是正确的语法.“++x"是什么意思?意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆