Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision |
python_notes [2023/12/31 19:14] – [Chained comparisons] raju | python_notes [2023/12/31 19:54] – [List of comparison operators] raju |
---|
Why? | Why? |
| |
A: The ''<'' and ''=='' are comparison operators. If a, b, c, …, y, z are expressions and op1, op2, …, opN are comparison operators, then in python a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once. | A: The ''<'' and ''=='' are comparison operators. If a, b, c, …, y, z are expressions and op1, op2, …, opN are comparison operators, then in python, a op1 b op2 c ... y opN z is equivalent to a op1 b and b op2 c and ... y opN z, except that each expression is evaluated at most once. |
| |
So ''3 < 4 == True'' is equivalent to ''3 < 4 and 4 == True'' which evaluates to ''True and False'' which turns out to be ''False''. | So ''3 < 4 == True'' is equivalent to ''3 < 4 and 4 == True'' which evaluates to ''True and False'' which turns out to be ''False''. |
| |
Ref:- https://docs.python.org/3/reference/expressions.html#comparisons | Ref:- |
| * https://docs.python.org/3/reference/expressions.html#comparisons - describes the above rule and also gives a list of comparison operators |
| |
| ==== List of comparison operators ==== |
| <code> |
| "<" | ">" | "==" | ">=" | "<=" | "!=" |
| | "is" ["not"] | ["not"] "in" |
| </code> |
| |
| Ref:- https://docs.python.org/3/reference/expressions.html#comparisons |
===== tasks ===== | ===== tasks ===== |
* [[get urls in a url]] | * [[get urls in a url]] |