Simply try converting it to an int and then bailing out if it doesn’t work.
try:
val = int(userInput)
except ValueError:
print("That's not an int!")
See Handling Exceptions in the official tutorial.
More Related Contents:
- How to check if string input is a number?
- Python check for integer input
- How to convert a string to integer entered in input functon? [duplicate]
- Determine the type of an object?
- Change column type in pandas
- What’s the difference between `raw_input()` and `input()` in Python 3?
- Sending data from HTML form to a Python script in Flask
- Immutable vs Mutable types
- Can’t send input to running program in Sublime Text
- Store different datatypes in one NumPy array?
- Can pandas automatically read dates from a CSV file?
- List vs tuple, when to use each? [duplicate]
- How do I find numeric columns in Pandas?
- Fastest way to convert a dict’s keys & values from `unicode` to `str`?
- Complex numbers in python
- How to input matrix (2D list) in Python?
- What does dtype=object mean while creating a numpy array?
- Why does object.__new__ work differently in these three cases
- Type hinting in Python 2
- How to check if a variable is a function in Python?
- the bytes type in python 2.7 and PEP-358
- Python: Can a subclass of float take extra arguments in its constructor?
- Possible to enforce type hints?
- Identifying the data type of an input
- Validating user input strings in Python
- How to finish sys.stdin.readlines() input?
- Can i set float128 as the standard float-array in numpy
- How to obtain the keycodes in Python
- win32: simulate a click without simulating mouse movement?
- Python: How to get input from console while an infinite loop is running?