在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 PIL和CV对 图片的读取,显示,裁剪,保存实现方法

PIL 图片操作 读取图片 img = Image.open(“a.jpg”) 显示图片 im.show() # im是Image对象,im是numpy类型,通过Image.f...

python 常见字符串与函数的用法详解

strip去除空格 s = ' abcd efg ' print(s.strip()) #去除所有空格 print(s.lstrip()) #去除左边空格 print(s.rs...

对python中的os.getpid()和os.fork()函数详解

如下所示: import os import sys import time processNmae = 'parent' print "Program executing...

简单了解Django模板的使用

简单了解Django模板的使用

模板标签include的使用 {%include"police/module/carousel.html"withimgs=imgsdiv_id='#carousel-index'%}...

解决tensorflow测试模型时NotFoundError错误的问题

错误代码如下: NotFoundError (see above for traceback): Unsuccessful TensorSliceReader constructor...