Python operators: Difference between revisions

From wikinotes
Line 1: Line 1:
= Operators =
= Equality Greater/Less Than =
<source lang="python">
<blockquote>
if ( x = 1 ) :            #regular if statement
<syntaxhighlight lang="python">
if (not( x =1 )) :        #if not statement
==  /  !=      # equal/not-equal
if (x = 1) and (y=2) :    #if and statement
is  /  is not # same /not-same instance
if (x > 10) and (x < 20) : #if or statement
>= /  <=     # greater/less than
</source>
</syntaxhighlight>
</blockquote><!-- Equality Greater/Less than -->


= bitwise operators =
= bitwise operators =

Revision as of 00:53, 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 bits