在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检测lvs real server状态

复制代码 代码如下:import httplibimport osimport time def check_http(i):    try: &...

在Linux下使用Python的matplotlib绘制数据图的教程

在Linux下使用Python的matplotlib绘制数据图的教程

如果你想要在Linxu中获得一个高效、自动化、高质量的科学画图的解决方案,应该考虑尝试下matplotlib库。Matplotlib是基于python的开源科学测绘包,基于python软...

Python转换时间的图文方法

Python转换时间的图文方法

time模块常用的中时间的转换。 python中的时间戳:通俗讲就是某个时刻的时间,单位是秒; 获取当前时间的时间戳: time.time() 1)没有参数, 2)返回从1970年1月1...

使用python 将图片复制到系统剪贴中

需要安装pywin32,pillow 依赖包 #coding:utf-8 import win32clipboard as clip import win32con from PI...

python实现简单图片物体标注工具

python实现简单图片物体标注工具

本文实例为大家分享了python实现简单图片物体标注工具的具体代码,供大家参考,具体内容如下 # coding: utf-8 """ 物体检测标注小工具 基本思路: 对要标注的图...