Python isdigit()メソッド

Python 字符串Python 文字列


説明

Python isdigit() メソッドは、文字列が数字のみで構成されているかどうかを検出します。0 と正の数に対してのみ有効です。

構文

isdigit() メソッドの構文:

str.isdigit()

パラメータ

  • なし。

戻り値

文字列が数字のみを含む場合は True を返し、それ以外の場合は False を返します。

例

以下の例は isdigit() メソッドの使用例を示しています:

例

#!/usr/bin/python # -*- coding: UTF-8 -*- str = "123456" # 文字列は数字のみを含む print (str.isdigit()) str = "this is string example....wow!!!" print (str.isdigit()) str = "0" print (str.isdigit()) str = "-1" print (str.isdigit())

上記の例の出力結果は次のとおりです:

True
False
True
False

Python 字符串Python 文字列

その他の拡張