Skip to main content
Noble Desktop/2 min read

Division in Python

Python Workflow

1

Set Up venv

python -m venv .venv — isolated environment per project.

2

Install Dependencies

pip install -r requirements.txt — pin versions for reproducibility.

3

Write & Test

Write functions; test with pytest as you go.

4

Run & Deploy

python script.py locally, deploy to your platform of choice.

Master Python at Noble Desktop

Noble Desktop's Python Programming Immersive covers AI APIs, data analysis, and modern Python development.

In this video, we're going to look at how to use Division in Python

Video Transcription

Hi, My Name is Art, and I Teach Python at Noble Desktop. in This Video, I'm Going to Show You Division. by Now, You Probably Know That Math is Simple in Python. Two Plus Two Will Get You Four, Two Minus Two Will Get You Zero, and Two Times Two Will Get You Four. However, It's Slightly Different with Division.

There are three division types in Python. The first is regular division. Five divided by three will give you a result. The second type of division is floor division. Floor division is how many times three can fit into five. So, in this case, it's only once. Floor division is useful when you need to get a whole number, as it rounds down. An example of this is if you have seven people and you want to split them into two teams. Seven divided by two using floor division will give you a whole number.

The opposite of floor division is modulus. Modulus (or percentage sign) will give you the remainder. For example, if you feed three into five, you will get a remainder of two. Modulus is useful when you need to get the remainder.

Python also has the function divmod which returns two values in a tuple. The first value is the product of floor division, and the second value is the product of modulus division. You can unpack the tuple and assign the values to variable names.

In my next video, I'm going to show you how to do a very popular problem called checking if a number is even or odd. Please watch it. Thank you.