Python字串isdecimal()方法

Python字串isdecimal()方法檢查字串是否僅由十進位字元組成,此方法僅存在於unicode對象上。

注意 - 與Python 2不同,所有字串在Python 3中表示為Unicode。以下是示例。

語法

以下是isdecimal()方法的語法 -

str.isdecimal()

參數

  • NA

返回值

  • 如果字串中的所有字元都為十進位,則此方法返回true,否則返回false

示例

以下示例顯示了isdecimal()方法的用法 -

#!/usr/bin/python3

str = "this2018"
print (str.isdecimal())

str = "123434"
print (str.isdecimal())

當運行上面的程式,它產生以下結果 -

False
True

上一篇: Python字串 下一篇: Python列表