Open In App

Python String isalpha() Method

Last Updated : 13 Nov, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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)

Output
True
False

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() Method

string.isalpha()

Parameter:

  • No parameters are required.

Return Type:

  • Returns True if all characters in string are alphabetic (A-Z, a-z) and False otherwise.

Example of isalpha() Method

String with Space

Python
s = "Hello World"
print(s.isalpha())

Output
False

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())

Output
False

Explanation: Here, s contains numbers (123), so isalpha() returns False.


Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy