Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:not': 0.03; 'else:': 0.03; 'beginner': 0.05; 'float': 0.07; 'string': 0.09; 'converted': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'def': 0.12; 'simplest': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'saying': 0.22; 'guys': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'raise': 0.29; 'converting': 0.30; 'message-id:@mail.gmail.com': 0.30; 'stuff': 0.32; "we're": 0.32; 'fri,': 0.33; 'except': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'catch': 0.60; 'most': 0.60; 'determine': 0.67; 'dont': 0.67; '20,': 0.68; 'fails,': 0.84; 'subject:check': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=kstYoAO9/jGgr5LAWt3S7QeVvkr4oOJQSDfFImz8SbQ=; b=KuPSgr5HuZ3ca1P9IQ2ZvlEARjlZHnYzV77b48IgnV3i/hDetuwpZIA+FdPYJ9YoKF ZA/nqZ8FGQyFdsE+z8mZFd2FGQTTTRCuU+1AcaxTUiwpzFonkbWehKCd4gCkBygkyZEG gzRL7c2TMRxaxkEWyMM3+gja295eGOVD3leK+SQBjqhIy19fPd7IxWfVk/itF5VhKH/m nkWeXpbmK7CQhLAN5//fipH906mVEXmUIkPMytvLOAYRU0tjMnR2OTb95FEc/F1Y6R0+ Cw9VoIPpdvZpimqX/lEpMPWd+w53fPKOBM64Jixe0omT5erVisqnhZ08NydW1DMd8G+S HeGw== X-Received: by 10.236.229.133 with SMTP id h5mr2006720yhq.64.1403245408751; Thu, 19 Jun 2014 23:23:28 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Fri, 20 Jun 2014 00:22:47 -0600 Subject: Re: how to check if a value is a floating point or not To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403245837 news.xs4all.nl 2966 [2001:888:2000:d::a6]:43346 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73447 On Fri, Jun 20, 2014 at 12:14 AM, Nicholas Cannon 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