Python3 isalpha()方法

Python3 字串 Python3 字串


描述

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

語法

isalpha()方法語法:

str.isalpha()

參數

  • 無。

返回值

如果字串至少有一個字元並且所有字元都是字母或文字則返回 True,否則返回 False。

實例

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

實例

#!/usr/bin/python3

str = "zaixian"
print (str.isalpha())

# 字母和中文文字
str = "zaixianIT研修"
print (str.isalpha())

str = "zaixian example....wow!!!"
print (str.isalpha())

以上實例輸出結果如下:

True
True
False

Python3 字串 Python3 字串