Behaviour of increment and decrement operators in Python

后端 未结 9 1951
无人共我
无人共我 2020-11-22 05:26

I notice that a pre-increment/decrement operator can be applied on a variable (like ++count). It compiles, but it does not actually change the value of the vari

9条回答
  •  無奈伤痛
    2020-11-22 06:04

    In Python, a distinction between expressions and statements is rigidly enforced, in contrast to languages such as Common Lisp, Scheme, or Ruby.

    Wikipedia

    So by introducing such operators, you would break the expression/statement split.

    For the same reason you can't write

    if x = 0:
      y = 1
    

    as you can in some other languages where such distinction is not preserved.

提交回复
热议问题