How to Use String isalpha() Method in PythonPython Basics


The isalpha() method checks if a string consists of only letters.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

str1 = 'ABCDabcd'
str2 = "ABCD abcd"
str3 = "ABCDabcd@"
str4 = "ABCDabcd1!"

print (str1.isalpha())
print (str2.isalpha())
print (str3.isalpha())
print (str4.isalpha())

Output:

True
False
False
False

Syntax

str.isalpha()

Parameters

The method doesn’t take any parameters.

Return Value

It returns True or False, depending upon whether the string contains only letters.

© 2024 Learnwithgpt.org, all rights reserved. Privacy Policy | Contact Us