Python3 isalpha()方法

Python3 字符串 Python3 字符串


描述

Python isalpha() 方法檢測字符串是否只由字母組成。

語法

isalpha()方法語法:

str.isalpha()

參數(shù)

  • 無。

返回值

如果字符串至少有一個字符并且所有字符都是字母則返回 True,否則返回 False

實例

以下實例展示了isalpha()方法的實例:

#!/usr/bin/python3

str = "python" #純字母的字符串
print (str.isalpha())

str = "編程獅" #中文字符串
print (str.isalpha())

str = "W3CSchool example....wow!!!"# 有字母,數(shù)字,其他符號的字符串
print (str.isalpha())

以上實例輸出結(jié)果如下:

True
True
False

Python3 字符串 Python3 字符串