Home  >  Article  >  Backend Development  >  How to check whether a string consists of letters in python: string.isalpha()

How to check whether a string consists of letters in python: string.isalpha()

Y2J
Y2JOriginal
2017-05-18 15:08:153351browse

python string.isalpha() method

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

Syntax:

str.isalpha()

Parameters:
The following are detailed parameters:
Not applicable
Return value :
It returns true if all characters in the string are letters and there is at least one character, otherwise it returns false.
For example:

#!/usr/bin/python
str = "this";  # No space & digit in this string
print str.isalpha();
str = "this is string example....wow!!!";
print str.isalpha();

This will output the following results:

True
False

[Related recommendations]

1. Python Free Video Tutorial

2. isalpha in Python 2.7 does not support unicode

The above is the detailed content of How to check whether a string consists of letters in python: string.isalpha(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn