Last Updated : 13 Nov, 2024
The isalpha() method checks if all characters in a given string are alphabetic. It returns True if every character in the string is a letter and False if the string contains any numbers, spaces, or special characters.
Let’s start with a simple example of using isalpha()
Python
s1 = "HelloWorld"
res1 = s1.isalpha()
print(res1)
s2 = "Hello123"
res2 = s2.isalpha()
print(res2)
Explanation: The string s1 are contains only alphabetic characters, so isalpha() returns True but the string s2 contains non-alphabetic characters so isalpha() returns False
Syntax of isalpha() MethodParameter:string.isalpha()
s = "Hello World"
print(s.isalpha())
Explanation: Since s contains a space which is not an alphabetic character, so isalpha() returns False.
String with Numbers Python
s = "Python123"
print(s.isalpha())
Explanation: Here, s contains numbers (123), so isalpha() returns False.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4