In this source code example, we will demonstrate how to use the Python string isalpha() method to check if all characters in a string are alphabetic.
Python
Python String
Use the Python string isalpha() method to check if all characters in a string are alphabetic.
The alphabetic characters are characters defined as letters in the Unicode character database.
It returned True because the string 'Rock' contains only alphabetic characters.
The following example returns False because the string 'John Cena' contains a space:
The following example returns False because the string contains a number:
Python string isalpha() method example
The following example uses the isalpha() method to check if a string contains alphabetic characters:name = 'Rock'
print(name.isalpha())
Output:
True
name = 'John Cena'
print(name.isalpha())
Output:
False
name = 'John Cena 123'
print(name.isalpha())
Output:
False
The following example returns False because the string is empty:
name = ''
print(name.isalpha())
Output:
False
Related Python String Examples
- Python string literals
- Python string length example
- Python String join() method example
- Python string split() method example
- Python String index() method example
- Python string find() method example
- Python string startswith() method example
- Python string endswith() method example
- Python String lower() method example
- Python String upper() method example
- Python string title() method example
- Python string capitalize() method example
- Python string islower() method example
- Python string istitle() method example
- Python string isupper() method example
- Python string swapcase() method example
- Python string strip() method example
- Python string replace() method example
- Python string isdigit() method example
- Python string isdecimal() method example
- Python string isnumeric() method example
- Python string isalpha() method example
- Python string isalnum() method example
Comments
Post a Comment