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
- SyntaxError: unexpected EOF while parsing
- How do I lowercase a string in Python?
- How do I copy a file in Python?
- How can I reverse a list in Python?
- Manually raising (throwing) an exception in Python
- How do I copy a file in Python?
- can’t multiply sequence by non-int of type ‘float’
- Difference between del, remove, and pop on lists
- How can I reverse a list in Python?
- How to use the pass statement
- How to use filter, map, and reduce in Python 3
- What does enumerate() mean?
- Searching the student-t distribution table for values using python
- How to declare an array in Python?
- Use Gif Logo For Loading Screen In Kivy
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- Pig Latin Translator
- What is the difference between Python’s list methods append and extend?
- How can I make a time delay in Python? [duplicate]
- Python – TypeError: ‘int’ object is not iterable
- TypeError: ‘int’ object is not subscriptable
- sphinx.ext.autodoc: Keeping names of constants in signature
- are there dictionaries in javascript like python?
- How do you round UP a number?
- Understanding slice notation
- Iterating over dictionaries using ‘for’ loops
- How to define a two-dimensional array?
- how to sort pandas dataframe from one column
- Why am I seeing “TypeError: string indices must be integers”?
- How do you round UP a number?
- Understanding slice notation
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How do I update\upgrade pip itself from inside my virtual environment?
- How to open a file using the open with statement
- How to emulate a do-while loop?
- How do I update\upgrade pip itself from inside my virtual environment?
- How to comment out a block of code in Python [duplicate]
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- Using “with open() as file” method, how to write more than once? [duplicate]
- TypeError: list indices must be integers or slices, not str
- Why there is no do while loop in python
- How do I get a substring of a string in Python?
- How do I sort a dictionary by value?
- ImportError: DLL load failed: The specified module could not be found
- How do I sort a dictionary by value?
- How to prettyprint a JSON file?
- What does the “yield” keyword do?
- ImportError: DLL load failed: The specified module could not be found