isnumeric
isnumeric() is an in-built method in Python, which is used to check whether a string contains only numeric values or not.
isnumeric()是Python中的內置方法,用于檢查字符串是否僅包含數字值。
Numeric contain all decimal characters and the fraction type values like (Half (?), one fourth (?)). This method is different from isdecimal() Method because it can check other numeric values except only decimal characters (from 0 to 10).
數值包含所有十進制字符和分數類型值,例如(半(1/2),四分之一(?))。 此方法不同于isdecimal()方法,因為它可以檢查除十進制字符(0到10)之外的其他數字值。
Note:
注意:
Numeric values contains decimal characters (all digits from 0 to 9) and fractional part of the values like ?, ?.
數值包含十進制字符(從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.isnumeric();
Parameter: None
參數:無
Return type:
返回類型:
true - If all characters of the string are numeric then method returns true.
true-如果字符串的所有字符均為數字,則方法返回true 。
false - If any of the characters of the string is not a numeric then method returns false.
false-如果字符串中的任何字符都不是數字,則方法返回false 。
Example/program:
示例/程序:
# numeric values (decimal characters)
str1 = u"362436"
print str1.isnumeric()
# numeric values (no decimal)
str2 = u"??"
print str2.isnumeric()
# nemeric values (with decimals)
str3 = u"??3624"
print str3.isnumeric()
# numeric values with alphabets
str4 = u"Hello??3624"
print str4.isnumeric()
Output
輸出量
TrueTrueTrueFalse
Reference: String isnumeric()
參考: 字符串isnumeric()
翻譯自: https://www.includehelp.com/python/string-isnumeric-method-with-example.aspx
isnumeric