如何使用python判断字符串是纯数字

  介绍

小编给大家分享一下如何使用python判断字符串是纯数字,希望大家阅读完这篇文章后大所收获、下面让我们一起去探讨吧!

<强>

<强> <强>

1,str.isdigit ()

<强> <强>

<强> <强>

真的,否则返回错误的。

<强> <强>

isdigit()方法的实例:

str =, & # 39; 123456 & # 39;   print (str.isdigit()), #真正的   ,   时间=str “耿雨飞,   print (str.isdigit()), #假

<强> <强>

,这种方法只是针对Unicode对象。

Unicode,只需要在字符串前添加& # 39;u # 39;前缀即可。

<强> <强>

1,str.isnumeric ()

<强> <强>

<强> <强>

真的,否则返回错误的。

str =,“runoob2016"   print  (str.isnumeric()), #假   ,   时间=str “23443434”;   print  (str.isnumeric()), #真正的

看完了这篇文章,相信你对如何使用python判断字符串是纯数字有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

如何使用python判断字符串是纯数字