Python string isalpha() method

Python String isalpha() Method

Description

The isalpha() method checks whether a string consists of only alphabetic characters.

Syntax

The following is the syntax of the isalpha() method −

var.isalpha()

Parameters

None

Return Value

This method returns True if all characters in the string are alphabetic. If there is at least one non-alphabetic character, it returns False.

Example

The following example demonstrates the usage of the isalpha() method.

var = "Explicit is better than implicit."
var1 = var.isalpha()
print ("Original string:", var)
print ("Does it contain only letters?:", var1)
var = "TutorialsPoint"
var2 = var.isalpha()
print ("Original string:", var)
print ("Does it contain only letters?:", var2)
var = "www.tutorialspoint.com"
var3 = var.isalpha()
print ("Original string:", var)
print ("Does it contain only letters?:", var3)

When you run this program, it will produce the following output −

Original string: Explicit is better than implicit.
Does it contain only letters?: False
Original string: TutorialsPoint
Does it contain only letters?: True
Original string: www.tutorialspoint.com
Contains only letters?: False

Leave a Reply

Your email address will not be published. Required fields are marked *