脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python中isnumeric()方法的使用简介

Python中isnumeric()方法的使用简介

2020-07-01 09:55Python教程网 Python

这篇文章主要介绍了Python中isnumeric()方法的使用,isnumeric()方法的使用是Python入门中的基础知识,需要的朋友可以参考下

 isnumeric()方法检查字符串是否仅由数字组成。这种方法只表示为Unicode对象。

注意:要定义一个字符串为Unicode,只需前缀分配'u'引号。以下是示例。
语法

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

?
1
str.isnumeric()

参数

  •     NA

返回值

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

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

?
1
2
3
4
5
6
7
8
#!/usr/bin/python
 
 
str = u"this2009";
print str.isnumeric();
 
str = u"23443434";
print str.isnumeric();

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

?
1
2
False
True

延伸 · 阅读

精彩推荐