Skip to content

Programming & Web Development · Guide

What does // mean in Python?

It is floor division: divide, then round down to a whole number. Here is what it returns, the negative-number surprise, and the rest of Python's operators in one place.

The Nextversity teamProgramming & Web Development schoolUpdated August 10, 20265 min read

On this page
  1. The short answer
  2. The negative number surprise
  3. Floats in, floats out
  4. // and % are a pair
  5. The rest of Python's operators
  6. Where operators trip beginners
  7. Where this fits in learning Python

The short answer

// is floor division. It divides, then rounds the answer down to a whole number.

7 // 2      # 3
10 // 3     # 3
9 // 3      # 3

Compare it with normal division, which always gives a float:

7 / 2       # 3.5
9 / 3       # 3.0

Use // when you want whole units: how many full pages, how many complete boxes, how many whole minutes.

The negative number surprise

This catches everyone once:

-7 // 2     # -4, not -3

Floor division rounds down, meaning toward negative infinity, not toward zero. Minus three and a half rounds down to minus four.

If you want to round toward zero instead, use int() on a normal division:

int(-7 / 2)   # -3

Two different behaviors, both correct, for different jobs.

Floats in, floats out

7.0 // 2    # 3.0
7 // 2.0    # 3.0

The rounding still happens, but the type follows the inputs. If either side is a float, the result is a float with nothing after the decimal point.

// and % are a pair

Floor division gives the whole part, modulo gives what is left over:

seconds = 137
minutes = seconds // 60    # 2
leftover = seconds % 60    # 17
print(f"{minutes}m {leftover}s")   # 2m 17s

That pattern (whole units plus remainder) covers time formatting, pagination, currency splitting and dozens of other everyday jobs. divmod(137, 60) returns both at once as (2, 17).

The rest of Python's operators

Arithmetic

OperatorMeaningExample
+add3 + 2 gives 5
-subtract3 - 2 gives 1
*multiply3 * 2 gives 6
/divide (always float)3 / 2 gives 1.5
//floor division3 // 2 gives 1
%remainder3 % 2 gives 1
**power3 ** 2 gives 9

Comparison

== equal, != not equal, < > <= >= as you would expect. Note the double equals: a single = assigns a value, and mixing them up is a rite of passage.

Logical

and, or, not. Python spells them out rather than using symbols, which is one of the reasons its code reads well out loud.

Assignment shortcuts

x += 1 adds one to x. The same pattern works for -=, *=, /=, //= and %=.

Membership and identity

in checks whether something is in a collection: "a" in "cat" is True. is checks whether two names point at the same object, which is not the same as equality, and using is where you meant == is a classic subtle bug.

+ on strings joins them, * on a list repeats it, and % on a string does old-style formatting. Python operators change meaning by type, which is convenient and occasionally surprising.

Where operators trip beginners

  • Integer versus float division. In Python 3, / always returns a float. Old Python 2 tutorials behave differently, which is one more reason to ignore them.
  • Operator precedence. 2 + 3 * 4 is 14, not 20. Brackets cost nothing and make intent obvious.
  • Chained comparison. 1 < x < 10 is valid Python and does what it looks like, which is rarer than you would think across languages.

The official Python documentation on expressions is the authoritative reference, and the tutorial covers the same ground more gently.

Where this fits in learning Python

Operators are an hour of study and then a lifetime of use. The parts worth your attention next are conditions, loops and functions, which is where programs stop being calculators.

The Python certificate covers the language in order, the advanced certificate follows with structure and projects, and one subscription opens the whole Programming & Web Development school.

Divide with // when you want whole things. Use % for what is left. That is genuinely all there is to it.

Questions people ask

What does // mean in Python?

Floor division. It divides and then rounds the result down to the nearest whole number, so 7 // 2 gives 3. It is the counterpart to %, which gives the remainder.

What is the difference between / and // in Python?

A single slash always returns a float, so 6 / 3 is 2.0. A double slash rounds down to a whole number, so 7 // 2 is 3. Use // when you want whole units, like how many full boxes fit.

How does // work with negative numbers?

It rounds down toward negative infinity, not toward zero. So -7 // 2 is -4, not -3. This surprises people once and then makes sense: floor means floor, in both directions.

Does // always return an integer?

It returns an integer when both operands are integers. If either is a float, you get a float with no fractional part, so 7.0 // 2 is 3.0.

What does % mean in Python?

The remainder after division, called modulo. 7 % 2 is 1. It is commonly used to test whether a number is even, with n % 2 == 0, and to wrap values around a range.

Keep reading