Python中处理字符串之isalpha()方法的使用

yipeiwu_com6年前Python基础

 isalpha()方法检查字符串是否仅由字母组成。
语法

以下是islpha()方法的语法:

str.isalpha()

参数

  •     NA

返回值

如果字符串中的所有字符字母和至少有一个字符此方法返回true,否则返回false。
例子

下面的例子显示了isalpha() 方法的使用。

#!/usr/bin/python

str = "this"; # No space & digit in this string
print str.isalpha();

str = "this is string example....wow!!!";
print str.isalpha();

当我们运行上面的程序,它会产生以下结果:

True
False

相关文章

pandas dataframe的合并实现(append, merge, concat)

创建2个DataFrame: >>> df1 = pd.DataFrame(np.ones((4, 4))*1, columns=list('DCBA'), ind...

Python利用matplotlib做图中图及次坐标轴的实例

Python利用matplotlib做图中图及次坐标轴的实例

图中图 准备数据 import matplotlib.pyplot as plt fig = plt.figure() x = [1, 2, 3, 4, 5, 6, 7] y =...

python 将字符串转换成字典dict

复制代码 代码如下:JSON到字典转化:dictinfo = simplejson.loads(json_str) 输出dict类型 字典到JSON转化:jsoninfo = simpl...

Python查找第n个子串的技巧分享

Problem Python中str类自带的find、index方法可以返回第一个匹配的子串的位置,但是如果实际使用中需要查找第2个甚至第n个子串的位置该怎么办呢。也许有的码友可能会用到...

python smtplib模块自动收发邮件功能(二)

python smtplib模块自动收发邮件功能(二)

接上篇python smtplib模块自动收发邮件功能(一) ,用python smtplib模块实现了发送邮件程序了,那么接下来我们需要现在要解决的问题如何在 test_report\...