Python:Operators: Difference between revisions

From wiki
Jump to navigation Jump to search
No edit summary
Line 25: Line 25:
;bit-shift right
;bit-shift right


;a & b
:And
;a | b
:Or
;a ^ b
:Xor


==Self assign==
==Self assign==
Line 42: Line 34:
:Just as you would expect
:Just as you would expect


==Boolean==
;and or &
;and or &
:Logical and
:Logical and
;or or |
;or or |
:Logical or
:Logical or
 
; ^
:Logical Xor (exclusive or)
;not
;not
:Negate the result of the next expression
:Negate the result of the next expression

Revision as of 19:16, 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


Self assign

a += b
Add b to a, works with other operators and on strings too.

Compare

==, >, <, <=, >=, !=
Just as you would expect

Boolean

and or &
Logical and
or or |
Logical or
^
Logical Xor (exclusive or)
not
Negate the result of the next expression