本サイトで発生する可能性のあるErrorの一覧です。エラーコードを文字検索(Windows:Ctrl+f、MAC:⌘+f)してご使用下さい。
- SyntaxError
- NameError
- TypeError
- TypeError: unsupported operand type(s) for ***
- TypeError: list indices must be integers or slices, not float
- TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
- TypeError: can’t multiply sequence by non-int of type ‘list’
- TypeError: can’t multiply sequence by non-int of type ‘float’
- TypeError: ‘>’ not supported between instances of ‘str’ and ‘int’
- TypeError: ‘tuple’ object does not support item assignment
- TypeError: cannot unpack non-iterable int object
- TypeError: can only concatenate str (not “int”) to str
- TypeError: ‘set’ object is not subscriptable
- TypeError: unsupported operand type(s) for |: ‘set’ and ‘str’
- IndentationError
- ValueError
- ValueError: invalid literal for int() with base 10: ‘a’
- ValueError: 20 is not in list
- ValueError: too many values to unpack (expected 2)
- ValueError: not enough values to unpack (expected 3, got 2)
- ValueError: attempt to assign sequence of size 4 to extended slice of size 3
- ValueError: list.remove(x): x not in list
- OverFlowError
- ZeroDivisionError
- IndexError
SyntaxError
構文エラー
SyntaxError: invalid character in identifier
構文エラー:無効な文字を使用
全角スペースが使われている
全角スペースを使用すると「SyntaxError」が発生します。以下の例図では全角スペースが使われている場所に赤線を加えています。実際にはこの赤線は見えませんので、この全角スペースのエラーは初心者にはお手上げの典型的なケースの一つです。見つけ方は、地道にスペースを半角に置き換えて再実行する以外にありません。

上記一番下の例の様に、コメントを追加しただけなのにエラーが発生したという場合、#の左側の空白が全角であったと言うのはよくある例の一つです。
またif文やfor文の後のコロン(:)が全角になっている場合もこのエラーとなります。
SyntaxError: invalid syntax
構文エラー:無効な構文
if文の条件式の間違い
- if文の条件式には比較演算子の == を使用すべきところ、間違って代入演算子 = を使用することによりこのエラーが発生します。

- if+条件文の後にコロン(:)ではなく、間違ってセミコロン(;)になっている、又はコロン(:)が無い

- 条件式に else ~ が無い。正しくは例えば「 b = a if a < 10 else 10 」の様に条件式には else ~ を入れる必要がある。

SyntaxError: non-default argument follows default argument
構文エラー:デフォルト無しの引数の前にデフォルト有りの引数がある。
- 関数を定義するdef文で、デフォルト有りの引数の後にデフォルト無しの引数を置いてはいけません。以下のケースの場合、a1にデフォルトがついてますが、a2にはついていないのでエラーとなります。2番目の様にa2にもデフォルトをつけるか、3番目の様に順番を入れ替えてデフォルト有りのa1を最後にする必要があります。

SyntaxError: invalid non-printable character U+3000
構文エラー:無効な印刷不可文字 U+3000
listの中のカンマの後ろのスペースが全角(U+3000)になっているとこのエラーが発生する

SyntaxError: unexpected character after line continuation character
構文エラー:行継続文字の後に文字が入っている
バックスラッシュ(\)で行を継続する場合は、\の後に文字を入れてはいけません。

NameError
名前エラー
NameError: name ‘***’ is not defined
名前「***」が定義されていない
***の定義文が無い又は実行していない
変数もしくは関数 ***が定義されていない、又は以下の様に定義するコードを実行せずに参照した場合にこのエラーが出ます。

TypeError
変数型エラー
TypeError: unsupported operand type(s) for ***
***ではサポートされていない型
文字列(str型)の割り算はできない
a も b も文字列として数字を代入しており、文字列同士の割り算はエラーとなる。

TypeError: list indices must be integers or slices, not float
listのindexは、float(小数点数)ではなくint(整数)またはスライスでなければならない。

TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
list同士の演算子として ー はサポートしていない

TypeError: can’t multiply sequence by non-int of type ‘list’
シーケンス型変数に非整数(non-int)のlistを掛ける事はできない

TypeError: can’t multiply sequence by non-int of type ‘float’
シーケンス型変数に非整数(non-int)のfloatを掛ける事はできない

TypeError: ‘>’ not supported between instances of ‘str’ and ‘int’
str(文字列)とint(整数)では ‘>’ はサポートされていない
整数(int)の100ではなく文字列(str)の’100’とすれば比較演算子が使用できるのでエラーは回避できます。

TypeError: ‘tuple’ object does not support item assignment
tupleは要素の割り当てをサポートしない
要素の置換をするためには、listを使うか、tupleの場合は全要素を使って再定義する必要があります。

TypeError: cannot unpack non-iterable int object
intオブジェクトはiterableでは無いので展開できない
複数の変数に一つのintを代入しようとするとこのTypeErrorが出ます。intがfloatの場合は、TypeError: cannot unpack non-iterable float object となります。

TypeError: can only concatenate str (not “int”) to str
str(文字列)と接続できるのは(intではなく)strのみ
strと整数を足し算で接続したときに出るエラー。以下の場合は s1 + str(s2) にすればOK。

TypeError: ‘set’ object is not subscriptable
set(集合型)のオブジェクトはインデックス指定不可
set型の要素はindexで抽出はできません。

TypeError: unsupported operand type(s) for |: ‘set’ and ‘str’
| に対しては set と str の演算子はサポートしていない

IndentationError
インデントエラー
IndentationError: expected an indented block
期待されたインデントブロックが無い

IndentationError: unindent does not match any outer indentation level
インデントの戻しが前のインデントに一致していない

ValueError
値エラー
ValueError: invalid literal for int() with base 10: ‘a’
‘a’ は10進数として無効な文字
以下の様に ‘a’ という文字を int() 関数で整数化しようとするとValueエラーとなります。オプションの base = 16 (16進数)を使えば、’a’ → 10 と変換することが可能です。

ValueError: 20 is not in list
20 はlistの中に無い
.index()でlistに無い要素を検索した場合にValueErrorとなります。

ValueError: too many values to unpack (expected 2)
代入する値の数が多すぎる(変数は2つ)
定義する変数の数に対してより多い数の値を代入しようとするとこのValueErrorとなります。

ValueError: not enough values to unpack (expected 3, got 2)
代入する値の数が足りない(変数3つに対して値は2つ)
上記とは反対に定義する変数の数に対してより少ない数の値を代入しようとするとこのValueErrorとなります。

ValueError: attempt to assign sequence of size 4 to extended slice of size 3
展開したスライスのサイズ3に対して代入するsequenceのサイズが4
以下の例では、ls[::2]で抽出されるlistは[‘tokyo’, ‘fuchu’, ‘nerima’]の3つであるのに対して、代入しようとしている右辺はサイズが4なのでValueErrorとなります。
この場合、右辺を[‘東京’, ‘府中’, ‘練馬’]とすれば、問題なく置換できます。

ValueError: list.remove(x): x not in list
list.remove(x) xという要素がlistに無い
listに無い要素を使って remove メソッドを使うとValue Errorになる。

OverFlowError
オーバーフロー
OverflowError: cannot convert float infinity to integer
オーバーフロー:無限大は整数に変換できない
float型の変数は1e308 (10の308乗) までは数値を表現できる。1e309 (10の309乗) となるとfloat型は inf (無限大)となり、それをint関数を用いて整数に変換しようとするとオーバーフローエラーとなる。

ZeroDivisionError
ゼロ割り算エラー
ZeroDivisionError: division by zero
ゼロによる割り算はエラーとなります。

但し、numpy.arrayをゼロで割った場合は、Warningが出ますが inf(無限大)又は-inf(マイナス無限大) に置き換わり、エラーとはなりません。また、以下の様にnumpy.arrayでゼロをゼロで割ると nan (not a number/非数)となります。

IndexError
Indexエラー
IndexError: list index out of range
listのindexが範囲外。indexは0から始まることに注意
