How to check if a string contains a number in Python

A string contains a number if any of the characters are digits (0-9).

Solution for How to check if a string contains a number in Python : You can use str.isdigit() to check if a string contains a number Iterate through each character of a string. Check if any character is a digit by calling str.isdigit(char) on each character char.

Use any() and map() for a more compact solution.

s = "abc1"


how-to-check-if-a-string-contains-a-number-in-python