Hello guys. How are you all? I hope you all fine. In this tutorial we will learn about how to check if Input Is Integer in Python. so without wasting time lets learn about of this.
How to check if Input Is Integer in Python
check if Input Is Integer in Python
To check if Input Is Integer in Python Use isnumeric() you can easily check if input is integer or not. so now lets learn to check by this given below example.
inp = input("Enter the input ") print(inp.isnumeric())
Input :Enter the input 5 True
How to check if Input Is Integer in Python
To check if Input Is Integer in Python Use isdigit() you can easily check if input is integer or not. so now lets learn to check by this given below example.
num1 = input("Enter your number ") print("\n") if num1.isdigit(): print("Your input is Number ") else: print("Your input is string ")
Output :Enter your number 5 Your input is Number
Method 1 : Using isnumeric()
By using isnumeric() you can easily check if input is integer or not. so now lets learn to check by this given below example.
inp = input("Enter the input ")
print(inp.isnumeric())
Input :
Enter the input 5
True
Method 2 : Using isdigit()
By using isdigit() you can easily check if input is integer or not. so now lets learn to check by this given below example.
num1 = input("Enter your number ")
print("\n")
if num1.isdigit():
print("Your input is Number ")
else:
print("Your input is string ")
Output :
Enter your number 5
Your input is Number
Conclusion
It’s all About this Tutorial. Hope all methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you?
Also, Read