assert函数(python)

assert语句:

用以检查某一条件是否为True,若该条件为False则会给出一个AssertionError。

用法:

assert type(x)=int and x>=0

如果不满足后面的expression,则会弹出

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    assert type(n)==int and n>0
AssertionError
原文地址:https://www.cnblogs.com/fei-hsueh/p/3973280.html