In Python 2, division of two ints produces an int. In Python 3, it produces a float. We can get the new behaviour by importing from __future__
.
>>> from __future__ import division
>>> a = 4
>>> b = 6
>>> c = a / b
>>> c
0.66666666666666663
More Related Contents:
- How to manage division of huge numbers in Python?
- How do I get 4 instead of 4.0 in "Squirrels and nuts – 1" task? [closed]
- How do I parse a string to a float or int?
- Why does integer division yield a float instead of another integer?
- How do you round UP a number?
- Convert floats to ints in Pandas?
- Safest way to convert float to integer in python?
- Strange behaviour with floats and string conversion
- Convert float to string in positional format (without scientific notation and false precision)
- Round a floating-point number down to the nearest integer?
- What are the differences between the urllib, urllib2, urllib3 and requests module?
- How to return dictionary keys as a list in Python?
- Alternative to dict comprehension prior to Python 2.7
- How to properly round-up half float numbers?
- Python – ‘ascii’ codec can’t decode byte
- Django TemplateDoesNotExist?
- RGB Int to RGB – Python
- How to convert a string of space- and comma- separated numbers into a list of int? [duplicate]
- How do I check if raw input is integer in python 2.7?
- What is the difference between isinstance(‘aaa’, basestring) and isinstance(‘aaa’, str)?
- numpy float: 10x slower than builtin in arithmetic operations?
- How do convert unicode escape sequences to unicode characters in a python string
- Reversing bits of Python integer
- How to accomplish relative import in python
- What is a “callable” in Python?
- Uninstall python built from source?
- Is there a built-in or more Pythonic way to try to parse a string to an integer
- Reading integers from binary file in Python
- Get the “bits” of a float in Python?
- What arguments does Python sort() function have?