3

I checked the operator precedence in Python 3, and found that there is no assignment (=).

I want to know if assignment is an operator or not. If not, why are there so many "assignment operator" hits when Googled? What is the precedence relation with other real operators (bool operator, comparison operator, etc.)?

CrazyChucky
  • 3,263
  • 4
  • 11
  • 25
leo.zhang
  • 105
  • 3
  • 10
  • 2
    Many sites often gloss over details like this. It's convenient for them to call the = symbol (and the related in-place operators) an assignment operator, because that's what it is in many other languages. The best place to go for technically questions like this is the official Python documentation, [there you can see that `=` is actually a _statement_](https://docs.python.org/3/reference/grammar.html?highlight=grammar), not an operator. – Christian Dean Sep 12 '17 at 16:12

1 Answers1

6

No. An assignment is always a statement in Python.

That's why things like assignment within if statements, which is acceptable in some other languages, is forbidden in Python.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • 3
    It may be worth noting that you can chain assignments, which makes it look sort of like assignment is an operator, but that's not what's actually happening there. – kindall Sep 12 '17 at 16:07