Python Forum

Full Version: an input question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,
I just wanted to know how I can check if a string input is a number?
You can try to convert the str into an int or float and catch the exception if it fails.
Hello,
there are several ways. There are plenty of explanations available if you search online. You can also start with this tutorial on our forums:
https://python-forum.io/Thread-Validating-User-Input
As the above post said, there are several ways, one of which is to use the variable.is_integer()

var=input("Enter a value")
if var.isint() == True:
    return True
else:
    return False
Did you look through the docs for str , i.e. the list of methods?