Python Review · Membership, Logic, Walrus, Identity, Comparison Operators
Jan 23, 2016
|
Tech
Software
Membership
-
Checks if an element is in a container;
in, not in.
Logic
-
Connects multiple Boolean conditions and evaluate the overall outcome;
and, or, not.
Logic Extended
-
Performs 'bulk' logical checks, simplifying long logic sequences;
any(), all().
Walrus
-
Assigns a value within an expression and returns it for immediate use;
(var := expr).
Identity
-
Checks if two variables point to the same object in memory, not their values;
is, is not.
Comparison
| Operator |
Description |
Example |
Result |
== |
Equal |
5 == 5.0 |
True |
!= |
Not equal |
10 != 7 |
True |
> |
Greater than |
5 > 10 |
False |
< |
Less than |
"apple" < "banana" |
True |
>= |
Greater than or equal |
5 >= 5 |
True |
<= |
Less than or equal |
3 <= 2 |
False |
Note:
str comparison is based on Unicode encoding;
== compares values, is compares memory addresses.