In this program, we will check whether a string contains an integer or not.
Steps to solve the program
- Take input through the user.
- Create a variable and assign its value equal to 0.
- Use for loop to iterate over each character of the string.
- Check if the character in the string is an integer or not using isnumeric().
- If it is a number add it to the variable that we have created.
- If the value of the variable is greater than 0 then print True, else print False.
a = input("Enter string: ")
count = 0
for char in a:
if char.isnumeric():
count += 1
if count > 0:
print(True)
else:
print(False)
Output :
Enter string: Python123
True