LoginSignup
3
1

More than 5 years have passed since last update.

pythonで文字列をintに変換・変換出来るかを確認させる

Posted at

Pythonで文字列をint型に変換・変換出来るかを確認させる

Pythonで文字列や数値を文字列、数値に変換したい時に使うのは
文字列に変換したい時はstr(変数)
intに変換したい時はint(変数)

変換できるかどうかを調べるのは

isdigit(変数)
変数に入っているのが
数字だけであればTrue
数字以外が入っていればFalseを返す
小数点も文字列として扱ってしまうので
1クッションとして別の事をしないとFloat変換は出来ない

3
1
3

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
3
1