Python's operators are mostly the same as Java, similar in function, with the same level of operators, this blog will learn the python operator:
python and Java operators
| Python |
Java |
Describe |
| Or |
|| |
Logical OR |
| and |
&& |
Logic and |
| Not |
! |
Logical Non- |
| <,>,<=,>=,==,!= or <> |
<,>,<=,>=,==,!= |
Compare operations |
| Is,is not |
instanceof |
Identity verification |
| | |
| |
Bit or |
| & |
& |
Bit and |
| ^ |
^ |
Bit XOR or |
| <<,>> |
<<,>> |
Shift |
| +,-,*,/ |
+,-,*,/ |
Subtraction |
| % |
% |
Remainder |
| ~ |
~ |
Bit take-fill |
It is important to note that in Python and Java, some operators are overloaded, like "+", "%", and so on. As for the operational level, Python and Java almost, in fact, do not remember, with parentheses Bai, hehe, programmers are always very "lazy."
Here is an example
>>> A = 3 >>> b = 4 >>> B/2 + a 5 >>> b/(2.0 + a) 0.80000000000000 004 >>> B << 2 >>> A | 2 3 >>> A & 1 1 >> > A/2 1 >>> a 2 1 >>> B > A true >>> not True False >>> (5 + 4j) * (7-2j) (43+18j) >>> 2 is 3 False >>> 2 was not 3
true >>> 2 is 2 True >>>
Go: Python operator learning