Does a string contain a number?
Write a Python program to check whether a string contains a digit.
"python1", "python"
python1 has a number python has no number
Approach
any(ch.isdigit() for ch in text).
Solution
for text in ["python1", "python"]: has = any(ch.isdigit() for ch in text) print(text, "has a number" if has else "has no number")python1 has a number python has no number
Line by line
any() stops at the first True.
Learn the concept
New to this topic? Read the lesson, then come back.