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

2021-01-11 10:15:37 浏览数 (1)

参考链接: Python字符串| digits

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 人点赞