Question: how to check if a string contains only digits in python?
Answer: Use str. isdecimal() to check if a string contains only numbers. Call the built-in str. isdecimal() method on the target string str to return a boolean value that represents whether all characters of the string are numeric digits or not.