Write a Python Program to Check If a String Is a Number (Float)

Python Program to Check If a String Is a Number (Float)

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Check If a String Is a Number (Float)
Python Program to Check If a String Is a Number (Float)

Write a Python Program to Check If a String Is a Number (Float)

PROGRAM: Python Program to Check If a String Is a Number (Float)

/* Python Program to Check If a String Is a Number (Float) */

def isfloat(num):
try:
float(num)
return True
except ValueError:
return False

print(isfloat(‘s12’))
print(isfloat(‘1.123’))

OUTPUT:-
FALSE
TRUE

Leave a Reply

Your email address will not be published. Required fields are marked *