Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons

← Back to How to's
Edit on Github

# What Does // Mean in Python?

Written by:

## What Does // Mean in Python?

One of the many operators in Python is the double slash // operator, which refers to an integer division (or a division with no remainder/decimals) which is called Floor Division. When dividing two numbers using this // operator, the result will always be an integer, ignoring the decimal part of the result.

.css-1mog2v{overflow-x:hidden;width:100%;margin:10px 0;}.css-1bx5ylf{display:block;position:relative;}.css-j8laeu{border-radius:4px 4px 0 0;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;padding:0 6px;background:#00041A;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;}.css-1hzxxxg{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:start;-ms-flex-pack:start;-webkit-justify-content:flex-start;justify-content:flex-start;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;width:-webkit-fit-content;width:-moz-fit-content;width:fit-content;}.css-1g6csra{outline:2px solid transparent;outline-offset:2px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;transition-property:var(--chakra-transition-property-common);transition-duration:var(--chakra-transition-duration-normal);font-size:var(--chakra-fontSizes-md);padding-top:var(--chakra-space-2);padding-bottom:var(--chakra-space-2);-webkit-padding-start:var(--chakra-space-4);padding-inline-start:var(--chakra-space-4);-webkit-padding-end:var(--chakra-space-4);padding-inline-end:var(--chakra-space-4);color:var(--chakra-colors-blue-500);}.css-1g6csra:focus-visible,.css-1g6csra[data-focus-visible]{z-index:1;box-shadow:var(--chakra-shadows-outline);}.css-1g6csra:disabled,.css-1g6csra[disabled],.css-1g6csra[aria-disabled=true],.css-1g6csra[data-disabled]{cursor:not-allowed;opacity:0.4;}.css-b509i{margin-top:30px;height:2px;background:var(--chakra-colors-blue-500);border-radius:1px;}.css-1c1d3c2{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;-webkit-justify-content:center;justify-content:center;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:relative;white-space:nowrap;vertical-align:middle;outline:2px solid transparent;outline-offset:2px;line-height:1.2;border-radius:var(--chakra-radii-md);font-weight:var(--chakra-fontWeights-semibold);transition-property:var(--chakra-transition-property-common);transition-duration:var(--chakra-transition-duration-normal);height:var(--chakra-sizes-8);min-width:var(--chakra-sizes-8);font-size:var(--chakra-fontSizes-sm);-webkit-padding-start:var(--chakra-space-3);padding-inline-start:var(--chakra-space-3);-webkit-padding-end:var(--chakra-space-3);padding-inline-end:var(--chakra-space-3);color:var(--chakra-colors-white);}.css-1c1d3c2:focus-visible,.css-1c1d3c2[data-focus-visible]{box-shadow:var(--chakra-shadows-outline);}.css-1c1d3c2:disabled,.css-1c1d3c2[disabled],.css-1c1d3c2[aria-disabled=true],.css-1c1d3c2[data-disabled]{opacity:0.4;cursor:not-allowed;box-shadow:var(--chakra-shadows-none);}.css-1c1d3c2:active,.css-1c1d3c2[data-active]{background:var(--chakra-colors-gray-200);}.css-1c1d3c2:hover,.css-1c1d3c2[data-hover]{background:#ffffff29;}.css-8atqhb{width:100%;}.css-1qbr3jw{padding:0px;outline:2px solid transparent;outline-offset:2px;}.css-16jickz{height:290px;border-radius:0 0 4px 4px;overflow:hidden;}Loading...

The double slash // has the same function as the Python method math.floor (which we will discuss later), as its name implies, rounds the result down (rounds to its floor) to the closest integer.

In this article, we will review more thoroughly how the Floor Division differs from a normal division, how the // operator works with different types of numbers (negative numbers and decimal numbers) and some extra methods similar to a Floor Division.

## Difference Between Floor Division // and Regular Division /

A normal division / in Python will always return a number with its decimal part, that is, a floating number, while a floor division will always return an integer number.

The result of regular division (using the / operator) is 45/6=7.5, but using // has floored 7.5 down to 7.

We can see another example as follows:

Loading...

## Working with Negative Numbers in Floor Divisions

To understand how to work with negative numbers using floor division, we need to understand that the floor of a positive number is different from the floor of a negative number. For example, the floor of 3.4 is 3, but the floor of -3.4 is -4, not 3. For greater understanding, we could say that the floor of a positive number would be the integer below and that the floor of a negative number would be the integer that is above (maintaining the negative sign).

We can see another example as follows using the same numbers as before:

Loading...

## Working with Floats in Floor Divisions

When we work with float numbers using floor division, the result will always be a float number, and as we already know, the result will be the nearest integer rounded to its floor, but in this case, it will be represented by a float number.

Let's have a look at the following float-based floor division example:

Loading...

As a result, the floor division operation is carried out using floats, and a float with an integer returns the value rounded down to the nearest integer represented by the floats.

## Similar Methods of a Floor Division

In Python, there are several methods similar to operations with // (floor division). But, how would these other methods be useful to us? It all depends on our use case, in some situations we will find ourselves needing to handle only integers in our projects, and since floor division operations can get both integers and floats, we could use a hand in these cases.

This is where these two additional methods come in, which are math.floor() and math.ceil, they will allow us to manipulate the result so that it is always an integer.

### math.floor() Function in Python

Python comes with a built-in math module that includes a variety of practical calculating tools. The math.floor() function is one of the math module's built-in features. This function takes a numeric input and rounds it down to the closest integer to return the floor value.

Therefore, math.floor() is an alternative to the // operator since they accomplish the same goal in the background, but always returning an integer.

Let's have a look at the following example:

Loading...

### math.ceil() Function in Python

math.ceil() is an alternative to math.floor() but it will always round up to the nearest whole number rather than down.

For instance:

Loading...

## Summary

The next video will be of great help to better understand what was explained in this What Does // Mean in Python? article