Python字符串| isdecimal()方法与示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值