how to check if a value is a floating point or not
Ian Kelly
ian.g.kelly at gmail.com
Fri Jun 20 02:22:47 EDT 2014
On Fri, Jun 20, 2014 at 12:14 AM, Nicholas Cannon
<nicholascannon1 at gmail.com> wrote:
> Guys i am only a beginner at python most of the stuff you are saying i need to do i dont understand.
All we're saying is that the simplest and most accurate way to
determine whether a string can be converted to an int or a float is to
try converting it and see if it succeeds. If it fails, it will raise
an exception that you can catch using the try-except syntax. Here's
what your checkint function might look like:
def checkint(a):
try:
int(a)
except ValueError:
return False
else:
return True
More information about the Python-list
mailing list