I'm trying to check if a string only contains letters, not digits or symbols.
For example:
>>> only_letters("hello") True >>> only_letters("he7lo") False
Simple:
if string.isalpha(): print("It's all letters")
str.isalpha() is only true if all characters in the string are letters:
str.isalpha()
Return true if all characters in the string are alphabetic and there is at least one character, false otherwise.
Demo:
>>> 'hello'.isalpha() True >>> '42hello'.isalpha() False >>> 'hel lo'.isalpha() False
1.4m articles
1.4m replys
5 comments
57.0k users