Introduction
Setup
Operators
variable
String
Number
Dtype & Comment
Lists
Tuples
Sets
Dictionaries
if else statement
For Loop
While Loop
iterator & iterable
Pre-Built functions
Function
Decorators
generators
Types of errors
Exceptions Handling
OOP
Regular expression
Create module
OS module
Date module
Random module
Math
Statistics module
Exercise 1
Exercise 2
Exercise 3
Learn Data Structure & Algorithm
Learn Numpy
Learn Pandas
Learn Matplotlib
Learn Seaborn
Learn Statistics
Learn Math
Learn MATLAB
Learn Machine learning
Learn Github
Learn OpenCV
Learn Deep Learning
Learn MySQL
Learn MongoDB
Learn Web scraping
Learn Excel
Learn Power BI
Learn Tableau
Learn Docker
Learn Hadoop
Operators are used to doing a lot of work.
Example:
Like if you want to do sum of 2 and 2 then you have to use plus sign between these two numbers and this plus
sign is an operator.
Example:If you want to compare two number which is greater, less then you will need less than or
greater than operator.
Example: If want to set condition like if two words or numbers are equal or not equal then run the code
written inside the condition then you will need operators.
Example:If you want to use multiple condition and want that at least one should be true or all the
condition must be true then you will need operators.
Example:If you want to do any type of calculation like multiplication between number, summation,
subtraction, division, etc between numbers then you must need operators.
So we can say that operators are very important things which we will need to perform a lot of works using
python coding. There are too many operators available in python.
Let's see those operators which are available in python.
Assignment operators are used to assign values to a variable like assigning a value 6 in a variable x.
Operator sign | Example | Short Form |
---|---|---|
= | x=5 | x=5 |
+= | x=x+3 | x+=3 |
-= | x=x-4 | x-=4 |
*= | x=x*5 | x*=5 |
/= | x=x/6 | x/=6 |
%= | x=x%4 | x%=4 |
//= | x=x//5 | x//=5 |
**= | x=x**6 | x**=6 |
&= | x=x&7 | x&=7 |
|= | x=x|4 | x|=4 |
^= | x=x^2 | x^=2 |
>>= | x=x>>1 | x>>=1 |
<<= | x=x<<3 | x<<=3 |
Arithmetic operators are used for doing mathematical operations with numeric values like summation, division, multiplication, subtraction, etc.
Operator sign | Example |
---|---|
+ | 4+3 |
- | 4-4 |
* | 3*5 |
/ | 10/6 |
% | 5%4 |
// | 3//5 |
** | 8**6 |
Logical operators are used to combine conditional statements like we want to use multiple condition and want that all the condition must be True to run the code. To this we will use and operator.
Operator sign | Example | Uses |
---|---|---|
and | x>5 and y<6 | It returns a result if all conditions are true |
or | x>5 or y<6 | It returns a result if at least one condition is true |
not | x>5 not y<6 | It reverse the result |
Comparison operators are used to compare more than one or multiple values. Suppose we have a condition where we want that if first number is less than the second number then the written code inside the condition will run. To do this we will use less than operator.
Operator sign | Example | Name |
---|---|---|
== | x==5 | Equal |
!= | x!=3 | Not equal |
> | x>4 | Greater than |
< | x<5 | Less than |
>= | x>=6 | Greater than equal |
<= | x<=4 | Less than equal |
Membership operators are used to test if a sequence is present in an object.
Operator sign | Example | Use |
---|---|---|
== | x in z | It returns true if it find the value |
!= | x not in z | It returns false if it doesn't find the value |
Bitwise operators are used to compare a binary numbers.
Operator sign | Example | Use |
---|---|---|
& | AND | It sets each bit to 1 if both bits are 1 |
| | OR | It sets each bit to 1 if one of two bits is 1 |
^ | XOR | It sets each bit to 1 if only one of two bits is 1 |
~ | NOT | This operator inverts all the bits |
>> | LEFT SHIFT | This operator shift left by pushing zeros in from the right and let the leftmost bits fall off |
<< | RIGHT SHIFT | This operator shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off |
In python, identity operators are used to compare the objects. if they are not equal, but if they are actually the same object, with the same memory location then it returns true otherwise it returns false
Operator sign | Name | Use |
---|---|---|
is | z is X | It will return True if both variables are the same object |
is not | is not x | It will return false if both variables are not the same object |