One - One Code All

Blog Content

python中各种数字类型的判别(numerica, digital, decimal)

Python   2008-07-16 00:09:03
  1. isdigital()      --- 除汉子外

  2. isnumeric()   --- 除byte数字

  3. isdecimal()    --- 仅单、双字节数字

num = ['1', '1', 'Ⅷ', '一', b'50']
 
decimal = [i for i in num[:4] if i.isdecimal()]     # 仅单字节、双字节数字,byte数字报错
digital = [i for i in num if i.isdigit()]           # 非汉子
numeric = [i for i in num[:4] if i.isnumeric()]     # byte数字报错
 
print(decimal,digital,numeric, sep='\n')



上一篇:python中双冒号(::)的用法
下一篇:linux系统查看当前正在运行的服务

The minute you think of giving up, think of the reason why you held on so long.