0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Python]キャスト可能かを調べる

Posted at

これなに?

受け取った値がそもそもキャスト可能かどうか調べたいこと、ありますね?(開発では忌避されるべきですが
競プロとかでたまに使うので、実装しました。

方法

キャスト時に不可能と判断された場合ValueErrorが吐かれるので、これをキャッチする要領で実装します。

def isInt(val):
    try:
        int(val)
    except ValueError:
        return False
    else:
        return True
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?