博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
isnumeric_Python字符串isnumeric()
阅读量:2530 次
发布时间:2019-05-11

本文共 2286 字,大约阅读时间需要 7 分钟。

isnumeric

Python String isnumeric()
Python String isnumeric() function returns
True if all the characters in the string are numeric, otherwise
False. If the string is empty, then this function returns
False.

如果字符串中的所有字符均为数字,则Python String isnumeric()函数将返回True ,否则返回False 。 如果字符串为空,则此函数返回False

Python字符串isnumeric() (Python String isnumeric())

Numeric characters include digit characters, and all characters that have the Unicode numeric value property. Formally, numeric characters are those with the property value Numeric_Type=Digit, Numeric_Type=Decimal or Numeric_Type=Numeric.

数字字符包括数字字符,以及所有具有Unicode数字值属性的字符。 形式上,数字字符是具有属性值Numeric_Type =数字,Numeric_Type =十进制或Numeric_Type =数字的字符。

Let’s look at some examples of Python string isnumeric() function.

我们来看一些Python字符串isnumeric()函数的示例。

s = '2019'print(s.isnumeric())

Output: True because all the characters in the string are numerical.

输出: True因为字符串中的所有字符都是数字。

s = 'Hello 2019'print(s.isnumeric())

Output: False because some of the characters in the string are not numerical.

输出: False因为字符串中的某些字符不是数字。

s = ''print(s.isnumeric())

Output: False because it’s an empty string.

输出: False因为它是一个空字符串。

Let’s look into some examples with special Unicode characters that are numerical.

我们来看一些带有数字的特殊Unicode字符的示例。

s = '¼'  # 00bc: ¼ (VULGAR FRACTION ONE QUARTER)print(s)print(s.isnumeric())s = '⒈⒗'  #2488: ⒈ (DIGIT ONE FULL STOP), 2497: ⒗ (NUMBER SIXTEEN FULL STOP)print(s)print(s.isnumeric())

Output:

输出:

¼True⒈⒗True

打印所有Unicode数字字符 (Print all Unicode Numeric Characters)

We can use unicodedata module to print all the unicode characters that are considered as numeric.

我们可以使用unicodedata模块来打印所有被视为数字的unicode字符。

import unicodedatacount = 0for codepoint in range(2 ** 16):    ch = chr(codepoint)    if ch.isnumeric():        print(u'{:04x}: {} ({})'.format(codepoint, ch, unicodedata.name(ch, 'UNNAMED')))        count = count + 1print(f'Total Number of Numeric Unicode Characters = {count}')

Output:

输出:

0030: 0 (DIGIT ZERO)0031: 1 (DIGIT ONE)...ff16: 6 (FULLWIDTH DIGIT SIX)ff17: 7 (FULLWIDTH DIGIT SEVEN)ff18: 8 (FULLWIDTH DIGIT EIGHT)ff19: 9 (FULLWIDTH DIGIT NINE)Total Number of Numeric Unicode Characters = 800

I never thought that there will be 800 Unicode characters that are numeric. 🙂

我从没想过会有800个数字Unicode字符。 🙂

. 。
. 签出更多Python示例。

Reference:

参考:

翻译自:

isnumeric

转载地址:http://qlmzd.baihongyu.com/

你可能感兴趣的文章
小D课堂 - 新版本微服务springcloud+Docker教程_5-01分布式核心知识之熔断、降级
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-04 feign结合hystrix断路器开发实战下...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-03 feign结合hystrix断路器开发实战上...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_6-01 微服务网关介绍和使用场景
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-05熔断降级服务异常报警通知
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_6-03 高级篇幅之zuul常用问题分析
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_5-08 断路器监控仪表参数
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_6-02 springcloud网关组件zuul
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-1.快速搭建SpringBoot项目,采用Eclipse...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-4.在线教育后台数据库设计...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-3.热部署在Eclipse和IDE里面的使用...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_1-3.在线教育站点需求分析和架构设计...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-4.后端项目分层分包及资源文件处理...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_2-2.快速搭建SpringBoot项目,采用IDEA...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-5.PageHelper分页插件使用
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-6.微信扫码登录回调本地域名映射工具Ngrock...
查看>>
小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_5-8.用户模块开发之保存微信用户信息...
查看>>
Linux下Nginx安装
查看>>
LVM扩容之xfs文件系统
查看>>
Hbase记录-client访问zookeeper大量断开以及参数调优分析(转载)
查看>>