1. 程式人生 > >Python assert(斷言)

Python assert(斷言)

lin traceback int size eba type ont bsp one

Python assert(斷言)可以分別後面的判斷是否正確,如果錯誤會報錯

示例:

a = 1
assert type(a) is int
print(No problem)

輸出結果:

No problem

a = 1
assert type(a) is int
print(No problem)

輸出結果:

Traceback (most recent call last):
File "D:/test.py", line 3, in <module>
assert type(a) is int
AssertionError

Python assert(斷言)