my_str.isalpha())
Returns True
if all chars are alphabets in a string, Otherwise False
is returned.
my_str='plus2net'
print(my_str.isalpha()) # Output is False
my_str='Welcome'
print(my_str.isalpha()) # Output is True
my_str='#1234'
print(my_str.isalpha()) # Output is False
my_str='12.34'
print(my_str.isalpha()) # Output is False
text = "Python123"
print(text.isalpha()) # False (contains digits)
print(text.isalnum()) # True (contains letters and digits)
print(text.isdecimal()) # False (contains letters)
Check if a user's name input contains only letters:
name = input("Enter your name: ")
if name.isalpha():
print("Valid name")
else:
print("Invalid name")
text = "Hello World!"
print(text.isalpha()) # Output: False
name = input("Enter your name: ")
if name.isalpha():
print("Valid name.")
else:
print("Invalid input: Use alphabet characters only.")