Created
January 26, 2015 19:33
-
-
Save ucaiado/50a157cc5411866e682c to your computer and use it in GitHub Desktop.
Check numers in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def isfloat(x): | |
| try: | |
| a = float(x) | |
| except ValueError: | |
| return False | |
| else: | |
| return True | |
| def isint(x): | |
| try: | |
| a = float(x) | |
| b = int(a) | |
| except ValueError: | |
| return False | |
| else: | |
| return a == b | |
| def check_type(s): | |
| """Check the type of a string passed""" | |
| #define the possible types | |
| o_str, o_int = type('a'),type(1) | |
| o_float, o_list, o_null=type(1.1), type([]), type(None) | |
| if s[0]=="{": return o_list | |
| elif (s=='NULL') | (s==""): return o_null | |
| elif isfloat(s) : return o_float | |
| elif isint(s) : return o_int | |
| else: return o_str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment