アサーション
assert 条件式, 説明
i = 10 assert i <= 9, "i is out of range. i: " + str(i) # AssertionError: i is out of range. i: 10
↑のコードは↓と等価
if __debug__: if not i <= 9: raise AssertionError("i is out of range. i: " + str(i))
assert 条件式, 説明
i = 10 assert i <= 9, "i is out of range. i: " + str(i) # AssertionError: i is out of range. i: 10
↑のコードは↓と等価
if __debug__: if not i <= 9: raise AssertionError("i is out of range. i: " + str(i))