Python Crash Course
)}

# Arithmetic Operators

We're going to start off easy and look at basic arithmetic operators in Python.

The first operator which we already saw in the last video is the addition operator which is performed by the plus symbol

+

in the first cell of our jupyter notebook, we will input the following arithmetic operation:

``print﻿( 1 + 1 )``

`>> 2`

this should naturally output the result 2.

## Subtraction Operator

Another arithmetic operation in python is the subtraction operator. This is denoted by the minus symbol:

-

In the next cell we will input:

``print﻿( 1 - 1 )``

`>> 0`

## Multiplication Operator

The next arithmetic operation is denoted by the multiplication symbol:

`*`

``print﻿( 7 * 7 )``

`>> 49`

## Division Operator

The division operator is denoted by the division symbol:

/

``print﻿( 10 / 5 )``

`>> 2`

## Division (floor) Operator

The division floor operator is denoted by the double slash symbol:

//

this division operator behaves just like the single slash operator, it however rounds down to the nearest integer, for example:

``print﻿( 13 // 2 )``

`>> 6`

with the single division operator, the expected result would have been 6.5. However, the double slash operator would round down to the nearest integer.

## Modulus Operator

the modulus operator simply outputs the remainder of a division. It is denoted with the following symbol:

%

``print﻿( 6 % 2 )``

`>> 0`

the result we got is 0, since dividing 6 by 2 gives us a remainder of 0

Now the modulus of 9 and 2:

``print﻿( 9 % 2 )``

`>> 1`

will result in 1 since 9 divided by 2 will produce a remainder of 1.

## Exponent Operator

The exponent operator is denoted by the double asterisk symbol:

**

``print﻿( 6 ** 2 )``

`>> 36`

## Order of Operation

Another important thing to note is that python follows the order of operation. for example:

``print﻿( 6 + 9 * 3 + 3 )``

`>> 36`

the output is 36, since as per the order of operation multiplication must occur first.

9 * 3 = 27

27 + 6 = 33

33 + 3 = 36

if you want to ensure that addition occurs, you can make use of parentheses. As per the order of operations, they occur before multiplication, like so:

``print﻿( ( 6 + 9 ) * ( 3 + 3 ) )``

`>> 90`

6 + 9 = 15

27 + 6 = 33

33 + 3 = 36

Feedback Summary
4.8
8 students
5

75%
4

25%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.