HELP Im currently using a book, but it seems like its wrong or something. This is what I enter:
round(10)
10
>>> round(10.0)
10
>>> round(10.2)
10
>>> round(8.7)
9
>>> round(4.5, 1)
4.5
>>> round(4.5, 2)
4.5
>>> round(4.5, 3)
4.5
>>> round (4.5)
4
>>> round(4.5)
4
Here is what the book says should happen:
round(10)
10
>>> round(10.0)
10.0
>>> round(10.2)
10.0
>>> round(8.7)
9.0
>>> round (4.5)
5
coldspeed95
407k106 gold badges745 silver badges798 bronze badges
1 Answer 1
Python2.7
>>> round(10.0)
10.0
>>> round(10.0, 0)
10.0
Python3.4, 3.5, and 3.6
>>> round(10.0)
10
>>> round(10.0, 0)
10.0
>>>
Two takeaways:
roundin python3 returns anint(when it can) while in python2 returnsfloat(always).- Read a book for python3!
answered Jun 21, 2017 at 19:09
coldspeed95
407k106 gold badges745 silver badges798 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
anon
For me round(10.0) is returning 10. Using Python3.6.1
LOL
Ok...im using 3.5.1, is that it?
coldspeed95
@LOL Can confirm, 3.5 shows the same behaviour. Now you can safely assume you're reading the wrong book. Cheers.
Explore related questions
See similar questions with these tags.
lang-py
round(10.0, 1)--> 10.0. The docs say "digits (default 0 digits)." NOTE: This is for Python 2.7x