Operators of Python

Operators of Python

Operators Of Python


Operators of python is either a special symbol or keyword used to perform operation on variable or value. Python have different kind of operators to perform different kind of operations. The value that the operator operates on is called the operand.

Assignment Operator Of Python:

The = sign is  a known as assignment operator and used to assign value to computer memory.The following statements showing using assignment operator to assign value

For example:

a = 2                #this statement will assign value 2 variable a

 Program for demonstration of assignment operator 

Output

 

 

Arithmetical Operators of Python:

Arithmetical operators are used to perform arithmetical operation like addition, subtraction, multiplication, division etc.

Arithmetical Operator Table-

Operator Name meaning
+ Addition Operator Add two number or unary plus
Subtraction Operator Subtract right operand from the left or unary minus
* Multiplication Operator Multiply two operands
/ True division Operator Divide left operand by the right one and returns results into float
% Modulus Operator Returns remainder of the division of left operand by the right
// Floor division Operator Divide left operand by the right one and returns results into whole number adjusted to the left in the number line
** Exponent Operator Returns value of left operand raised to the power of right

Program for demonstration of arithmetical operators of Python

Output

Value of r =7

 

Value of r = 3

 

Value of r = 10

 

Value of r = 2.5

 

Value of r = 2

 

Value of r = 1

 

Value of r 25

 

 

 

Short-hand Assignment Operators of Python

there are various  short-hand assignment operators in Python like a +=5 .It will add 5 to the variable a and later will assign the result to variable ‘a’. .It is equivalent to a =a +5. These short-hand assignment operators are also known as compound assignment operators.Following are the short-hand assignment operators in python:

Operator meaning
+= It adds right operand to the left operand and assign the result to left operand
-= It subtracts right operand from the left operand and assign the result to left operand
*= It multiplies right operand with the left operand and assign the result to left operand
/ Divide left operand by the right one and returns results into float
/= It divides left operand with the right operand and assign the result to left operand
%= It takes modulus using two operands and assign the result to left operand
//= Performs exponential (power) calculation on operators and assign value to the left operand

Program for demonstration of short-hand assignment operators of python

Output

 Relational or Comparison Operators of  python

Comparison operators are used to compare values on left hand side and right hand side  and fine relation between them. Following are the relational operators in python:

Operator Name meaning
< less than operator Returns True if left operand is less than the right
> Greater than operator Returns True if left operand is greater than the right
== equal to operator Returns True if both operands are equal
!= Not equal to operator Returns True if operands are not equal
>= Greater than or equal to operator Return True if left operand is greater than or equal to the right
<= Less than or equal to operator Return True if left operand is less than or equal to the right

Program for demonstration of relational operators of python

 Logical Operators of Python 

Logical operators are used to combine two or more conditions and perform the logical operations using Logical AND, Logical OR and Logical NOT. Following are the logical operators in python:

Operator Name meaning
and Logical AND operator Returns True if both operands return True
or Logical OR operator Returns True if either of the operands True
not Logical NOT operator Returns True if either of operands is False and returns False if operands is True

Program for demonstration of logical operators of  Python

Output


 

Leave a Reply

Your email address will not be published. Required fields are marked *