int vs. float
Erik
python at lucidity.plus.com
Fri Feb 10 15:46:16 EST 2017
More information about the Python-list mailing list
Fri Feb 10 15:46:16 EST 2017
- Previous message (by thread): int vs. float
- Next message (by thread): int vs. float
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 10/02/17 19:15, Peter Pearson wrote: > On Fri, 10 Feb 2017 13:59:45 +0200, Amit Yaron <amit at phpandmore.net> wrote: >> Use: >> >> try: >> num=int(str) >> except ValueError e: >> print "Error: not an integer" > > What should happen if the user types "1.0"? > > To be flexible about this possibility, you could accept the number > as a float, and then complain if int(num) != num. Python 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> 0.99999999999999995 1.0 >>> f = float("0.99999999999999995") >>> i = int(f) >>> i 1 >>> f 1.0 >>> i == f True >>> E.
- Previous message (by thread): int vs. float
- Next message (by thread): int vs. float
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list