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中的內(nèi)置方法,用于檢查字符串是否僅包含十進制字符。
Note:
注意:
Decimal characters contain all digits from 0 to 9.
十進制字符包含從0到9的所有數(shù)字。
String should be Unicode object - to define a string as Unicode object, we use u as prefix of the string value.
字符串應(yīng)為Unicode對象-要將字符串定義為Unicode對象,我們使用u作為字符串值的前綴。
Syntax:
句法:
String.isdecimal();Parameter: None
參數(shù):無
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
輸出量
TrueFalseFalseReference: String isdecimal()
參考: 字符串isdecimal()
翻譯自: https://www.includehelp.com/python/string-isdecimal-method-with-example.aspx
總結(jié)
以上是生活随笔為你收集整理的Python字符串| isdecimal()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转载] 【数学问题】利用python求
- 下一篇: 大脑应对危机的模式_危机的完整形式是什么