python

当前位置:中华考试网 >> python >> python编程基础 >> 文章内容

python如何判断字符是否为字母

来源:中华考试网  [2020年10月21日]  【

  Python中有一个方法isalpha(),该方法可以检测字符串是否只由字母组成。如果字符串至少有一个字符并且所有字符都是字母则返回 True,否则返回 False。

  语法:

1

str.isalpha()

  代码示例:

1

2

3

4

5

6

7

8

9

10

11

#!/usr/bin/python

# coding=utf-8

 

str = "php";

print str.isalpha();

 

str = "php中文网";

print str.isalpha();

 

str = "this is string example....wow!!!";

print str.isalpha();

  输出结果:

1

2

3

True

False

False

责编:fushihao
  • 会计考试
  • 建筑工程
  • 职业资格
  • 医药考试
  • 外语考试
  • 学历考试