Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22872

Python Morsels: What does // mean in Python?

$
0
0

Python's // operator performs "floor division" (a.k.a. "integer division"). It always rounds down the result to the nearest integer while dividing.

The / operator

The / operator is the division operator in Python.

When / is used between two numbers, you'll always get the exact (as exact as Python can manage) result back:

>>> 5/22.5
>>> 5/22.5

Unlike some programming languages, / in Python does not act any differently when used between integers; in Python 3 that is. In Python 2, division between two integers would would the result downward to the nearest integer:

>>> 5/2# Python 22
>>> 5/2# Python 22

But in Python 3, division between two integers always returns a floating point number with the exact result:

>>> 4/22.0
>>> 4/22.0

The // operator between integers

The // operator is the …

Read the full article: https://www.pythonmorsels.com/integer-division/


Viewing all articles
Browse latest Browse all 22872

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>