Behaviour of increment and decrement operators in Python

后端 未结 9 2012
无人共我
无人共我 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 05:48

    There are no post/pre increment/decrement operators in python like in languages like C.

    We can see ++ or -- as multiple signs getting multiplied, like we do in maths (-1) * (-1) = (+1).

    E.g.

    ---count
    

    Parses as

    -(-(-count)))
    

    Which translates to

    -(+count)
    

    Because, multiplication of - sign with - sign is +

    And finally,

    -count
    

提交回复
热议问题