Python check if input is number or letter; Through this tutorial, i am going to show you how to check if user input is a number, letter or string in python.
Python Program To Check user Input is a Number or Letter
- How to check if a string contains numbers in python
- How to check if a string contains letters and numbers in python
How to check if a string contains numbers in python
- Get input value from the user in program.
- Check whether a string contains number or not by using isdigit() function.
- Print the result.
# python code to check whether a string # contains only digits or not # str1 = input("Please enter number or string or both") # checking & printing messages if str1.isdigit(): print("str contains a number") else: print("str does not contain a number")
After executing the program, the output will be:
Execution 1 of program check if a string contains numbers in python:
Please enter number or string or both 1234 str contains a number
Execution 2 of program check if a string contains numbers in python:
Please enter number or string or both test556 str does not contain a number
How to check if a string contains letters in python
- Get input value from the user in python.
- Check whether a string contains letter or not by using isalpha() function.
- Print the result.
# python code to check whether a string # contains only letter or not # str1 = input("Please enter anything ") # Code to check if str1.isalpha(): print("String contains only letters") else: print("String doesn't contains only letters")
After executing the program, the output will be:
Execution 1 of program check if a string contains letter in python:
Please enter anything here String contains only letters
Execution 2 of program check if a string contains numbers in python:
Please enter anything hello34 String doesn't contains only letters
Recommended Python Tutorials
Recommended:-Python Program For Calculator
Recommended:-Python Program to Find Strong Number
Recommended:-Python Program to Convert cm to Feet and Inches
Recommended:-How to Reverse a List in Python
Recommended:-Python Program to Convert Celsius to Fahrenheit
Recommended:-Python Program to Find Standard Deviation
Recommended:-Python Program to Check Perfect Number
Recommended:-Python Program to Display Calendar
Recommended:-Python Program to Print Alphabets from A to Z
Recommended:-Python Program to Find Roots of Quadratic Equation
Recommended:-Python Program to Find the Variance
Recommended:-How to Check Python Program Execution Time
Recommended:-Python Program Find Day of Week For Given Date
Recommended:-Python Program to Print Sum of All Array Elements
Recommended:-Python Program to Find the GCD of Two Numbers
Recommended:-Python Program to Find the LCM of the Array Elements