isdecimal()方法檢查字串是否只包含小數字元。 這個方法只在Unicode對象存在。
注:不像在Python2,在Python3所有的字串表示為Unicode,如下面的例子。
語法
以下是 isdecimal() 方法的語法 -
str.isdecimal()
參數
-
NA
返回值
如果字串中的所有字元都是十進位的該方法返回:true,否則為:false。
示例
下麵的示例顯示 isdecimal()方法的使用。
#!/usr/bin/python3 str = "this2016" print (str.isdecimal()) str = "23443434" print (str.isdecimal())
當我們運行上面的程式,會產生以下結果 -
False True