Advertisement
CamolaZ

is_Float() with try except

Sep 13th, 2022
616
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | Source Code | 0 0
  1. # Check if a string represents a float in Python
  2. def is_float(a_string):
  3.     try:
  4.         float(a_string)
  5.         return True
  6.     except ValueError:
  7.         return False
  8. print(is_float('2.2.2'))
  9. print(is_float('2.123'))
  10. # Returns:
  11. # False
  12. # True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement