Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 isalpha() Method

Python3 isalpha() Method

Python3 Strings Python3 Strings


Description

The Python isalpha() method checks whether a string consists only of letters or characters.

Syntax

Syntax of the isalpha() method:


str.isalpha()

Parameters

Return Value

Returns True if the string has at least one character and all characters are letters or characters, otherwise returns False.

Example

The following example demonstrates the isalpha() method:

Example

#!/usr/bin/python3

str

=

"runoob"

print

(

str

.

isalpha

(

)

)

Letters and Chinese characters

str

=

"runoobRunoob Tutorial"

print

(

str

.

isalpha

(

)

)

str

=

"Runoob example....wow!!!"

print

(

str

.

isalpha

(

)

)

The output of the above example is:


True
True
False

More examples:

Example

Example 1: a string containing only letters

print

(

"HelloWorld"

.

isalpha

(

)

)

 

Output: True

Example 2: a string containing digits

print

(

"Hello123"

.

isalpha

(

)

)

 

Output: False

Example 3: a string containing spaces

print

(

"Hello World"

.

isalpha

(

)

)

 

Output: False

Example 4: a string containing special characters

print

(

"Hello#World"

.

isalpha

(

)

)

 

Output: False

Example 5: an empty string

print

(

""

.

isalpha

(

)

)

 

Output: False

Example 6: a string containing an underscore

print

(

"Hello_World"

.

isalpha

(

)

)

 

Output: False

Example 7: a string containing non-ASCII letters

print

(

"HélloWorld"

.

isalpha

(

)

)

 

Output: True, because e with an acute accent is a letter


Python3 Strings Python3 Strings