Difference between revisions of "Python:Operators"
Jump to navigation
Jump to search
m (→Self assign) |
|||
Line 2: | Line 2: | ||
Most operators work as usual. | Most operators work as usual. | ||
− | == | + | ==Less obvious assignment== |
+ | |||
+ | ;<int> * <string> | ||
+ | :Repeat <string> <int> times. Negative <int>s return an empty string. | ||
;a / b | ;a / b | ||
− | :Divide to floating point | + | :Divide to floating point. In python2 the result datatype is determined by the arguments datatype i.e. both arguments int => result is int. |
;a // b | ;a // b |
Revision as of 21:02, 7 August 2019
Most operators work as usual.
Less obvious assignment
- <int> * <string>
- Repeat <string> <int> times. Negative <int>s return an empty string.
- a / b
- Divide to floating point. In python2 the result datatype is determined by the arguments datatype i.e. both arguments int => result is int.
- a // b
- Divide to integer (truncated, not rounded)
- a % b
- Modulo
- a ** b
- Power
- a << b
- bit-shift left
- a >> b
- bit-shift right
- a & b
- And
- a | b
- Or
- a ^ b
- Xor
Self assign
- a += b
- Add b to a, works with other operators and on strings too.
Compare
- ==, >, <, <=, >=, !=
- Just as you would expect
- and or &
- Logical and
- or or |
- Logical or
- not
- Negate the result of the next expression