Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is assignment an operator in Python?

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.)?

like image 448
leo.zhang Avatar asked Sep 14 '25 10:09

leo.zhang


1 Answers

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.

like image 124
Daniel Roseman Avatar answered Sep 16 '25 23:09

Daniel Roseman