an input question - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: an input question (/thread-28321.html) |
an input question - saratha - Jul-14-2020 Hello everyone, I just wanted to know how I can check if a string input is a number? RE: an input question - Yoriz - Jul-14-2020 You can try to convert the str into an int or float and catch the exception if it fails.
RE: an input question - j.crater - Jul-14-2020 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 RE: an input question - BitPythoner - Jul-14-2020 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 RE: an input question - ndc85430 - Jul-15-2020 Did you look through the docs for str , i.e. the list of methods?
|