In different Python versions, the value of the round function will appear in different situations
In Python2.7, the definition of round function is that if the input value is the same distance from both sides, then take the even side
~ python2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> round(0.5)
1.0
In Python3, the round function is defined as rounding.
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> round(0.5)
0
The guy upstairs used ipython, which is based on python2, so the definition also follows Python2.
In different Python versions, the value of the round function will appear in different situations
In Python2.7, the definition of round function is that if the input value is the same distance from both sides, then take the even side
In Python3, the round function is defined as rounding.
The guy upstairs used ipython, which is based on python2, so the definition also follows Python2.
round(number, ndigits=None)
refers to the number of decimal places to be retained, the default is None
Try round(4.5)