Python Operators

In this article / tutorial we will learn about Python all basic operators. When we process, calculate and compare values or variables then we use operators. Operators have too much important role in any kind of programming language. Without Operators programming is nothing. Operators make relations between two or more variables and functions. There are many types of Operators you can see below

  1. Arithmetic Operators
  2. Assignment Operators
  3. Comparison Operators
  4. Logical Operators
  5. Identity Operators
  6. membership Operators
  7. Bitwise Operators



1) Python Arithmetic Operators

Arithmetic operators are used for mathematics or calculations. There are following arithmetic operators in Python

See examples to understand how to use Arithmetic Operators (Click Here)

%Modulus/Remainderz % r




2) Python Assignment Operators

Assignment Operators are used for assigning the values to variables. . You can see below the types of Assignment Operators in Python.

Check Examples to understand how to use Assignment Operators (Click Here)

OperatorsNamesExamplesIs equal to this
+=Add Equalz+=9z=z+9
-=Subtract Equalz-=9z=z-9
*=Multiply Equalz*=9z=z*9
/=Divide Equalz/=9z=z/9
%=Modulus Equalz %= 9z=z%9
**=Exponent Equalz**=9z=z**9
//=Floor Equalz//=9z=z//9
&=And Equalz&=9z=z&9
|=Or Equalz|=9z=z|9



3)Python Comparison Operators

Comparison operators are used to comparing the values and variables. There are following Types of Comparison Operators

Check Examples to understand how to use Comparison Operators (Click Here)

==Equal toz==r
!=Not Equal toz!=r
>Greater Thanz>r
<Smaller Thanz<r
>=Greater Than or Equal toz>=r
<=Smaller Than or Equal toz<=r



4)Python Logical Operators

We use logical operators commonly to combine the two conditional statements of the comparison operators. For example if your age is more than 20 years and less than 22 years. See following the types of the logical operators

Check Examples to understand how to use Logical Operators (Click Here)

andLogical ANDz>4 and z<9
orLogical ORz<4 or z>9
notLogical NOTnot(z<4 and z>9)



5)Python Identity Operators

We use Identity Operators to compare the two objects memory locations. See below the Identity Operators

Check Examples to understand how to use Identity Operators (Click Here)

isReturn true if both variables are with same objectsZ is R
is notReturn false if both variables are not with same objectZ is not R



6)Python membership Operators

We use membership operators to check membership/value in a sequence like, lists, strings and tuples. you can see below the membership operators

Check Examples to understand how to use membership Operators (Click Here)

inReturn true if value is present in the objectZ in R
not inReturn false if value is not present in the objectZ not in R



7)Python Bitwise Operators

We use Bitwise Operators to compare the binary numbers. There are following Bitwise Operators you can see below

&Binary ANDCopy a bit if bit exist in both operands
|Binary ORCopy a bit if bit exist in at least one operand from two
^Binary XORCopy a bit if bit is set in one operand but not in both
~Binary Open Compliment/NOTIt inverts the bits
<<Binary Left ShiftLeft Operands Value is shifted left
>>Binary Right ShiftLeft Operands value shifted Right




Get More Python Tutorials