isdecimal() is an in-built method in Python, which is used to check whether a string contains only decimal characters or not.
isdecimal()是Python中的内置方法,用于检查字符串是否仅包含十进制字符。
Note:
注意:
Decimal characters contain all digits from 0 to 9. 十进制字符包含从0到9的所有数字。 String should be Unicode object - to define a string as Unicode object, we use u as prefix of the string value. 字符串应为Unicode对象-要将字符串定义为Unicode对象,我们使用u作为字符串值的前缀。
Syntax:
句法:
String.isdecimal();
Parameter: None
参数:无
Return type:
返回类型:
true - If all characters of the string are decimal characters then method returns true. true-如果字符串的所有字符均为十进制字符,则method返回true 。 false - If any of the characters of the string is not a decimal character then method returns false. false-如果字符串中的任何字符都不为十进制字符,则方法返回false 。
Example/program:
示例/程序:
# str1 with only decimal characters
str1 = u"362436"
print str1.isdecimal ()
# str2 with alphabets and decimal characters
str2 = u"Hello36"
print str2.isdecimal ()
# str3 with alphabets and special characters
str3 = u"@Hell36#"
print str3.isdecimal ()
Output
输出量
True
False
False
Reference: String isdecimal()
参考: 字符串isdecimal()
翻译自: https://www.includehelp.com/python/string-isdecimal-method-with-example.aspx
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有