Python operators: Difference between revisions
From wikinotes
Line 17: | Line 17: | ||
x >> n # bitwise shift by n bits | x >> n # bitwise shift by n bits | ||
~x # invert bits | ~x # invert bits | ||
</syntaxhighlight> | |||
bitwise operators function on binary numbers. | |||
<syntaxhighlight lang="python"> | |||
int('101', 2) # 4 in binary | |||
int('100', 2) | int('010', 2) == int('110', 2) # bitwise or sets binary digit | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- bitwise operators --> | </blockquote><!-- bitwise operators --> |
Revision as of 00:56, 31 July 2021
Equality Greater/Less Than
== / != # equal/not-equal is / is not # same /not-same instance >= / <= # greater/less than
bitwise operators
x | y # bitwise or x ^ y # bitwise exclusive and x & y # bitwise and x << n # bitwise shift by n bits x >> n # bitwise shift by n bits ~x # invert bitsbitwise operators function on binary numbers.
int('101', 2) # 4 in binary int('100', 2) | int('010', 2) == int('110', 2) # bitwise or sets binary digit