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?

【Python】ValueError: invalid literal for int() with base 10: ''

Last updated at Posted at 2025-09-02

はじめに

Python でコードを書いていたとき,以下のようなエラーが出てしまいました.

ValueError: invalid literal for int() with base 10: ''

今回は,このエラーの原因について,記事に書いておこうと思います.
今回エラーが出てしまったコードの例は,以下の通りです.

一見,普通に実行できそうです.

なお,このコードは,別関数(Handler) を呼び出しています.

try:
    Handler(1, 2)
    
finally:
    print("finish")

エラー文の解読

このエラー文を読むと,10進数の整数に変換できない値がint()関数に渡されたことを伝えています.

エラーの原因

エラーの原因は,finally:の前の行の空行にありました.
空行のインデントがなかったために,エラーが出ていました.

終わりに

Python は便利ですが,たまにエラーの原因が突き止められなくて,困りますね.
同じエラーにぶつかった人の助けになればと思います.

0
0
4

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?