Python isnumeric()方法

Python 教程 · 2019-02-02 13:13:36

描述

Python isnumeric() 方法检测字符串是否只由数字组成。这种方法是只针对unicode对象。

注:定义一个字符串为Unicode,只需要在字符串前添加 'u' 前缀即可,具体可以查看本章节例子。

语法

isnumeric()方法语法:

str.isnumeric()

参数

  • 无。

返回值

如果字符串中只包含数字字符,则返回 True,否则返回 False

实例

以下实例展示了isnumeric()方法的实例:

#!/usr/bin/python

str = u"this2009";  
print str.isnumeric();

str = u"23443434";
print str.isnumeric();

以上实例输出结果如下:

False
True

点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html

查看所有标签

Head First jQuery

Head First jQuery

Ryan Benedetti , Ronan Cranley / O'Reilly Media / 2011-9 / USD 39.99

Want to add more interactivity and polish to your websites? Discover how jQuery can help you build complex scripting functionality in just a few lines of code. With Head First jQuery, you'll quickly g......一起来看看 《Head First jQuery》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

html转js在线工具
html转js在线工具

html转js在线工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具