在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使用wxPython实现计算器

本文实例为大家分享了wxPython实现计算器的具体代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- ########################...

python增加矩阵维度的实例讲解

numpy.expand_dims(a, axis) Examples >>> x = np.array([1,2]) >>> x.shape...

python 2.6.6升级到python 2.7.x版本的方法

1.下载python2.7.x wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz 2.解压并编译安装 tar -...

浅谈django中的认证与登录

认证登录 django.contrib.auth中提供了许多方法,这里主要介绍其中的三个: 1  authenticate(**credentials)  ...

Python生成词云的实现代码

Python生成词云的实现代码

1 概述 利用Python生成简单的词云,需要的工具是cython,wordcloud与anaconda. 2 准备工作 包括安装cython,wordcloud与anaconda. 2...