Python String isalpha()

Python string isalpha() method is mainly used to check if the string is the alphabet or not. The isalpha() method returns true if all the characters in the string are alphabets. Otherwise, it returns false.

Python String isalpha()

Syntax – string.isalpha()

Parameters – None

Return Value – Returns True if all the characters in the string are alphabets; otherwise, it returns false.

Valid Alphabets

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

Example 1 – Let’s take a look at few use cases of isalpha() method.

# Valid alphabet
text1= "HelloWorld"
print(text1.isalpha())

# contains whitespace
text2 = "Hello World"
print(text2.isalpha())

# contains Special Character
text3 = "HelloWorld!!"
print(text3.isalpha())


# contains Alphanumeric
text3 = "Hello123"
print(text3.isalpha())

Output

True
False
False
False

Example 2 – A practical example of the isalpha() method to check if the entered username is a valid alphabet or not.

username = input("Choose a username:")

if username.isalnum() == True:
	print("The entered username is ", username)
else:
	print("Please enter a valid usernameSrin.")

Output

Choose a username:ItsMycode
The entered username is ItsMycode
Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like
Python Bool()

Python bool()

Table of Contents Hide bool() Syntax bool() Parametersbool() Return ValueExample of bool() function in Python Python’s bool() function converts a given value into Boolean(True or False) using the standard truth testing…
View Post