Python字符串| isdigit()方法与示例
isdigit() is an in-built method in Python, which is used to check whether a string contains only digits or not.
isdigit()是Python中的內(nèi)置方法,用于檢查字符串是否僅包含數(shù)字。
Digit value contains all decimal characters and other digits which may represent power or anything related to this, but it should be a complete digit, like "3".
數(shù)字值包含所有十進(jìn)制字符和其他數(shù)字,這些數(shù)字可能表示冪或與此有關(guān)的任何東西,但它應(yīng)該是完整的數(shù)字,例如“ 3” 。
This method is different from isdecimal() method and isnumeric() method because first method checks only decimal characters and second method checks numeric values including decimal characters. And this (isdigit()) method will consider only digit.
此方法不同于isdecimal()方法和isnumeric()方法,因?yàn)榈谝粋€(gè)方法僅檢查十進(jìn)制字符,第二個(gè)方法檢查包括十進(jìn)制字符的數(shù)值。 并且此( isdigit() )方法將僅考慮digit。
Note:
注意:
Digits value contains decimal characters and other Unicode digits, fractional part of the value like ?, ? etc are not considered as digit.
數(shù)字值包含十進(jìn)制字符和其他Unicode數(shù)字,該值的小數(shù)部分(如?,?等)不視為數(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對(duì)象-要將字符串定義為Unicode對(duì)象,我們使用u作為字符串值的前綴。
Syntax:
句法:
String.isdigit();Parameter: None
參數(shù):無(wú)
Return type:
返回類型:
true - If all characters of the string are digits then method returns true.
true-如果字符串的所有字符都是數(shù)字,則method返回true 。
false - If any of the characters of the string is not a digit then method returns false.
false-如果字符串中的任何字符都不是數(shù)字,則方法返回false 。
Example/program:
示例/程序:
# Only digits (decimal characters) str1 = u"362436" print (str1.isdigit())# digit value (no decimals but a digit) str2 = u"3" print (str2.isdigit())# numeric values but not any digit str3 = u"??" print (str3.isdigit())#digits, alphabets str4 = u"Hello3624" print (str4.isdigit())Output
輸出量
TrueTrueTrueFalseReference: String isdigit()
參考: 字符串isdigit()
翻譯自: https://www.includehelp.com/python/string-isdigit-method-with-example.aspx
總結(jié)
以上是生活随笔為你收集整理的Python字符串| isdigit()方法与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: [转载] 基于LSTM的股票预测模型_p
- 下一篇: ruby array_Ruby中带有示例