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

yipeiwu_com6年前Python基础

 isdigit()方法检查字符串是否只包含数字(全由数字组成)。
语法

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

str.isdigit()

参数

  •     NA

返回值

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

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

#!/usr/bin/python

str = "123456"; # Only digit in this string
print str.isdigit();

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

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

True
False

相关文章

网站渗透常用Python小脚本查询同ip网站

网站渗透常用Python小脚本查询同ip网站

旁站查询来源: http://dns.aizhan.com http://s.tool.chinaz.com/same http://i.links.cn/sameip/ http://...

分享一下如何编写高效且优雅的 Python 代码

分享一下如何编写高效且优雅的 Python 代码

本文部分提炼自书籍:《Effective Python》&《Python3 Cookbook》,但也做出了修改,并加上了作者自己的理解和运用中的最佳实践。 全文约 9956 字,读完可能...

对Python的多进程锁的使用方法详解

很多时候,我们需要在多个进程中同时写一个文件,如果不加锁机制,就会导致写文件错乱 这个时候,我们可以使用multiprocessing.Lock() 我一开始是这样使用的: impo...

Python 从列表中取值和取索引的方法

如下所示: name_list["zhangsan","lisi","wangwu"] #1.取值 print(name_list[0]) print(name_list[1])...

对Python 2.7 pandas 中的read_excel详解

导入pandas模块: import pandas as pd 使用import读入pandas模块,并且为了方便使用其缩写pd指代。 读入待处理的excel文件: df =...