Division in Python

Free Video Tutorial and Guide

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.

How to Learn Python

Master Python with hands-on training. Python is a popular object-oriented programming language used for data science, machine learning, and web development. 

Yelp Facebook LinkedIn YouTube Twitter Instagram