Starting Python..
Operators in Python :
Mainly there are seven differnt types of operators. They are as follows.
Mainly there are seven differnt types of operators. They are as follows.
- Arithmetic operators
- Assigment operators
- Comparison operators
- Logical operators
- Bitwise operators
- Identity operators
- Membership operators
1. Arithmetic Operators : (+, -, *, / , ** , %, // )
+ : Add two operands i.e. 2+3 =5
- : Subtract two operands i.e. 3-2 = 1
* : Multiply two operands i.e. 3*3= 9
/ : Divide two operands i.e. 4/2 =2
**: Left operand raise to the power of right 2**3 =8
// : Modulus operator : division that result into whole number adjusted to the left in the number line. i.e. 7//3 =2
- : Subtract two operands i.e. 3-2 = 1
* : Multiply two operands i.e. 3*3= 9
/ : Divide two operands i.e. 4/2 =2
**: Left operand raise to the power of right 2**3 =8
// : Modulus operator : division that result into whole number adjusted to the left in the number line. i.e. 7//3 =2
Below example of arithmetic operators are given below. Please practice and feel free to ask question if you find any problem.
2. Assignment operator : ( += , /= , %= , //= , **= )
When do we use assignment operator ?
Lets take an example for better understanding. We have three variable num1, num2, num3.
num3 = num1 + num2
num3 = num3 + num2
Now, the second line code can be rewritten as
num3+=num2
just making it a short hand code.
Below example of assignment operators are given below. Please practice and feel free to ask question if you find any problem.
When do we use assignment operator ?
Lets take an example for better understanding. We have three variable num1, num2, num3.
num3 = num1 + num2
num3 = num3 + num2
Now, the second line code can be rewritten as
num3+=num2
just making it a short hand code.
Below example of assignment operators are given below. Please practice and feel free to ask question if you find any problem.
3.Comparison Operators : ( > , < , == , != )
They are used for comparision two or more values.
> : True, if left operand is greater.
< : True, if left operand is less.
== : True, if both operands are equal.
!= : True, if left operand is not equal to right.
Below example of comparision operators are given below. Please practice and feel free to ask question if you find any problem.
4. Logical Operators : ( and , or , not )
There are three logical operators.
and : both condtion should be true
or : Any condtion can be true
not : not equal to
Below example of logical operators are given below. Please practice and feel free to ask question if you find any problem.
Comments
Post a Comment