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:
- Python check for integer input
- How can I check if string input is a number?
- Determine the type of an object?
- Immutable vs Mutable types
- Can’t send input to running program in Sublime Text
- Show default value for editing on Python input possible?
- Store different datatypes in one NumPy array?
- Can pandas automatically read dates from a CSV file?
- How to read keyboard-input?
- List vs tuple, when to use each? [duplicate]
- How do I find numeric columns in Pandas?
- Check if all elements of a list are of the same type
- How to get multiline input from the user [duplicate]
- Complex numbers in python
- How to test a function with input call?
- Finding the Values of the Arrow Keys in Python: Why are they triples?
- How to input matrix (2D list) in Python?
- What does dtype=object mean while creating a numpy array?
- How to find out if a Python object is a string?
- 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
- User input and command line arguments [closed]
- How to delete a specific line in a text file using Python?
- Python: Can a subclass of float take extra arguments in its constructor?
- Identifying the data type of an input
- Validating user input strings in Python
- How to finish sys.stdin.readlines() input?
- win32: simulate a click without simulating mouse movement?