Python Shorthand Operator?

后端 未结 3 372
终归单人心
终归单人心 2020-12-11 21:09

I was researching some information on the topic of trial division, and I came across this symbol in Python:

//=

I got this from here where

相关标签:
3条回答
  • 2020-12-11 21:20

    // is the floor division operator, therefore //= is simply the inplace floor division operator.

    0 讨论(0)
  • 2020-12-11 21:26

    // is integer division and the

    n //= p
    

    syntax is short for

    n = n // p
    

    except the value n is modified directly if it supports this.

    0 讨论(0)
  • 2020-12-11 21:31

    When you see an operator followed by an =, that is performing the operation and then assigning it into the variable. For example, x += 2 means x = x + 2 or add 2 to x.

    The // operator specifically does integer devision instead of floating point division. For example, 5 // 4 gives you 1, while 5 / 4 gives you 1.25 (in Python 3).

    Therefore, x //= 3 means divide x by 3 (in an integer division fashion), and store the value back into x. It is equivalent to x = x // 3

    0 讨论(0)
提交回复
热议问题