What is the purpose of the '==' operator when comparing vs '=' values?

First, note that I understand what is ==used to compare two expressions, and is =used to assign a value to a variable. However, python is such a clean language with minimal syntax requirements that seems like a simple operator for an ax. Also, I am not trying to start a discussion or discussion, but rather find out if there is something that I am missing to improve my programming knowledge.

As in (in python), we do not need to declare a variable, which should be an int or a string, and the language determines this based on the assigned value, why does the "if" operator simply determine what =is a comparison, not an assignment?
<w> Another example is that python got rid of many {} and [] in other languages ​​and simply used indentation because indentation and the use of curly braces are redundant. It seems to me that is if foo == goo:also redundant. But maybe there is something I don’t know about yet. Hence the question!

+5
source share
2 answers

One very simple reason python allows boolean expressions:

a = b == c

as well as multiple purposes:

a = b = c

a * (True False) , b c . a b (c). , .

, ( ) = if ( ), - , c, if. ( " , " ).


  • . , a __eq__ ( b __eq__, NotImplemented) - , (numpy.ndarray , __eq__, , , ndarray).
+11

. ,

a = b = c

a b c,

a = b == c

a True, False , b c .


, Python , , . , , , . .

+5

All Articles