In Python 3.x, 5 / 2
will return 2.5
and 5 // 2
will return 2
. The former is floating point division, and the latter is floor division, sometimes also called integer division.
In Python 2.2 or later in the 2.x line, there is no difference for integers unless you perform a from __future__ import division
, which causes Python 2.x to adopt the 3.x behavior.
Regardless of the future import, 5.0 // 2
will return 2.0
since that’s the floor division result of the operation.
You can find a detailed description at https://docs.python.org/whatsnew/2.2.html#pep-238-changing-the-division-operator
Related Posts:
- What do these operators mean (** , ^ , %, //)? [closed]
- What do these operators mean (** , ^ , %, //)? [closed]
- syntaxerror: “unexpected character after line continuation character in python” math
- Does Python have a ternary conditional operator?
- What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
- Is there a “not equal” operator in Python?
- What is the result of % in Python?
- numpy max vs amax vs maximum
- Is there a “not equal” operator in Python?
- IndentationError: unexpected indent error
- Putting a simple if-then-else statement on one line [duplicate]
- How can I do a line break (line continuation)?
- syntaxerror: “unexpected character after line continuation character in python” math
- TypeError: ‘float’ object is not callable
- `from … import` vs `import .` [duplicate]
- Error: all the input array dimensions except for the concatenation axis must match exactly
- syntaxerror: “unexpected character after line continuation character in python” math
- What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
- proper name for python * operator?
- What does the power operator (**) in python translate into?
- How do order of operations go on Python?
- Python: SyntaxError: keyword can’t be an expression
- What does numpy.gradient do?
- Python: OverflowError: math range error
- How can I use numpy.correlate to do autocorrelation?
- How can I convert radians to degrees with Python?
- Infinite integer in Python
- The tilde operator in Python
- Overflow / math range error for log or exp
- How do I find the distance between two points?
- How can I check for NaN values?
- Python – how to use the constant e^
- What does `<>` mean in Python?
- How to normalize a 2-dimensional numpy array in python less verbose?
- SyntaxError invalid token
- log2 in python math module
- How can I check for NaN values?
- Printing variables in Python 3.4
- How can I check if two segments intersect?
- python math domain errors in math.log function
- Error “‘type’ object has no attribute ‘__getitem__'” when iterating over list[“a”,”b”,”c”]
- How to fix ‘RuntimeWarning: divide by zero encountered in double_scalars’
- Is there a math nCr function in python?
- How do I compute derivative using Numpy?
- Inline for loop
- Python def marked as invalid syntax
- Is there a math nCr function in python? [duplicate]
- Using the AND and NOT Operator in Python [duplicate]
- Python a &= b meaning?
- OCaml mod function returns different result compared with %
- bash: syntax error near unexpected token `(‘ – Python
- Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
- TypeError: only size-1 arrays can be converted to Python scalars (matplotlib)
- Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
- Python Pandas Counting the Occurrences of a Specific value
- What does the c underscore expression `c_` do exactly?
- Count unique values per groups with Pandas
- Get unique values from a list in python [duplicate]
- How do you decode Base64 data in Python?
- Convert pandas Series to DataFrame
- TypeError: ‘type’ object is not subscriptable when indexing in to a dictionary
- Embedding in pytorch
- Check string “None” or “not” in Python 2.7
- re.search().TypeError: cannot use a string pattern on a bytes-like object
- Cannot uninstall Tensorflow
- Add Legend to Seaborn point plot
- Get key by value in dictionary
- How to add multiple values to a dictionary key in python?
- Where can I find a list of the Flask SQLAlchemy Column types and options?
- How can I install Python’s pip3 on my Mac?
- Python: Write array values into file
- use np.random.multinomial() in python
- pg_config executable not found
- Import error when trying to import tensorflow with gpu
- Removing Punctuation From Python List Items
- TypeError(“‘bool’ object is not iterable”,) when trying to return a Boolean
- “OverflowError: Python int too large to convert to C long” on windows but not mac
- Is there a list of Pytz Timezones?
- Flask example with POST
- How do I change the figure size with subplots?
- Clear terminal in Python [duplicate]
- ModuleNotFoundError: No module named ‘discord’
- No numeric types to aggregate – change in groupby() behaviour?
- Algorithm for solving Sudoku
- How to read pickle file?
- What is a “slug” in Django?
- Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll
- if else function in pandas dataframe
- Primality test in python [duplicate]
- Simple way to create matrix of random numbers
- pandas: multiple conditions while indexing data frame – unexpected behavior
- ‘instancemethod’ object has no attribute ‘__getitem__’ with class variables
- Python/Scikit-Learn – Can’t handle mix of multiclass and continuous
- Sorting list of lists by the first element of each sub-list
- Install py2exe for python 2.7 over pip: this package requires Python 3.3 or later
- “public” or “private” attribute in Python ? What is the best way?
- How to search for a string in text files?
- TypeError: ‘zip’ object is not subscriptable
- Pip: could not find a version. No matching distribution found
- Compare two columns using pandas