assert
一般用法是:
assert condition
用来让程序测试这个condition,如果condition为False则抛出一个AssertionError,逻辑上等同于
if not condition: raise AssertionError()
比如下面的例子
>>> assert 1==1>>> assert 1==0Traceback (most recent call last): File "", line 1, in assert 1==0AssertionError>>> assert True>>> assert FalseTraceback (most recent call last): File " ", line 1, in assert FalseAssertionError>>> assert 3<2Traceback (most recent call last): File " ", line 1, in assert 3<2AssertionError