Posted in: Python

# Arithmetic Operators in Python – Types (Unary and Binary) and Examples

In this tutorial, we are going to learn about Arithmetic Operators and their types in Python with examples.

Definition: Arithmetic Operators are used to perform mathematical operations like Addition, Substraction, Multiplication and Division.

There are mainly two types of arithmetic operators in Python:

1. Unary Operators
2. Binary Operators

### Unary Operators

Unary arithmetic operators perform mathematical operations only on one operand. The ‛+’ and ‛-’ are two unary operators. The unary operator minus (-) produces the negation of its numeric operand. The unary operator plus (+) returns the numeric operand without change.

#### Examples of Unary Operators

```>>> x=-5 #Negates the value of X
>>> x
-5
>>> x=+6 #Returns the same value
>>> x
6
```

### Binary Operators

Binary Operators are the operators that require two operands to perform any mathematical operation. They are written in infinix form, i.e. the operator is written in between the two operands.

#### Types of Binary Operators

There are mainly 7 types of Binary Operators available in Python:

2. Subtraction Operator
3. Multiplication Operator
4. Division Operator
5. Floor Division Operator
6. Modulo Operator
7. Exponent Operator

The ‛+’ operator in Python can be used with both the binary and unary form. If the addition operator is applied in between two operands, it returns the result as the arithmetic sum of operands.

```>>> 4+7 #Addition
11
10
```

The following table explains the syntax and semantics of the addition operator in Python, using its three numeric types, viz. Int, Float and complex.

### Subtraction (-) Operator

The ‘-‘ operator in Python can be used with binary and unary form. If the subtraction operator is applied in between two operands, that will calculate the difference between both of the operands and return it as output.

Example:

```>>> 7-4 #Subtraction
3
>>> 5-2 #Subtraction
3
```

Syntax and Semantics of Subtraction operator in Python:

### Multiplication (*) Operator

The ‘*’ operator in Python can only be used with binary form. The multiplication operator can be used between two operands that will result as the product of both the operands and return as output from the Python program.

Example:

```>>> 7*4 #Multiplication
28
>>> 5*2 #Multiplication
10
```

Syntax and Semantics of Multiplication Operator:

### Division (/) Operator

Division operator (/) in Python can be only operated or used with binary forms. It is used between two operands to calculate the quotient of operands and it return it as an output through the Python program.

Example:

```>>> 4/2 #Division
2.0
>>> 10/3
3.3333333333
```

Syntax and Semantics of Division Operator in Python:

## Floor Division (//) Operator

Floor Division (//) Operator in Python can be only used with binary forms. This Operator is used between two operands to get the quotient as the result of Python program and show it as output. Now, the difference is that the Floor Division operator ignoes the numbers after decimal point in the quotient and put a zero after decimal.

Example:

```>>> 4/2 #Floor Division
2
>>> 13/4 #Floor Division
3
```

Syntax and Semantics of Floor Division Operator:

### Modulo (%) Operator

Modulo (%) Operator is used between two operands to perform division and obtain the reminder as output from the program.

Example:

```>>> 10%4 #10 is divided by 4 and we got 2 as remainder
2
>>> 13%5
3
```

Syntax and Semantic of Modulo Operator:

### Exponent ** Operator

Exponent ** Operator is used to calculate the power or exponent of a number. To compute Xy(X raised to y power), the expression is written as X**y in Python. The exponent operator is also called Power operator.

Example:

```>>> 4**2 #calculate square of 4
16
>>> 2**3 #calculate cube of a number 2
8
```

Syntax and Semantics of Exponent operator: