# Operators in Python

In Programming, Python by Baqir Ali

Operators are the building blocks of an expression or a mathematical formula. such as 3*10 here 3 and 10 are operands and the * sign is the operator. The same is the case with python while building expressions we need different operators that functions differently.

The following are the operators that python supports.

• Basic mathematic/arithmetic operator
• Relational operator
• Assignment operator
• Arithmetic assignment operator
• Logical operator

### Arithmetic Operator in Python

Example 1:

``````a=10
b=20
sum=a+b
print("the sum is ",sum)``````

Output:

the sum is 30

Example 2:

``````a=20
b=3
div=a/b

Output:

Example 3:

``````a=20
b=3
div=a%b
print("the remainder is  ",div)``````

Outpu:

the remainder is 2

### Relational Operator in Python

Relational Operator is used to comparing values between two operands and returns true or false value. Relational operators are mostly used in loops and conditional statements.

Example 1:

``````a=20
b=3

Output:

Example 2:

``````a=20
b=20

Output:

### Assignment Operator in Python

Assignment operators are used to assigning values to the variables.

### Arithmetic Assignment Operator in Python

Here assignment operator is used with combination to an arithmetic operator to form an expression, such as a+=10

Example 1:

``````count=10
count+=1
print(count)
count*=2;
print(count)``````

Output:

11
22

#### Logical Operator in Python

Effects on relational expression’s results also AND, OR combines two or more Relational expressions,  Results will be returned either TRUE( 1 ) or FALSE ( 0 ) regards with specific situations.

Example 1:

``````a=10
b=20
c=15
print((a<b) and (b<c))``````

Output:

False

Explaining the above code, a=10 b=20, c=15 the first condition a<b which is 10<20 true, second condition b<c which is 20<15 false,in the caes of AND true and false will result to false.

Support us by sharing this post