Python中assert的用法

Python中assert的用法

 

Python中assert用来判断语句的真假,如果为假的话将触发AssertionError错误

如:

>>> a = 23
>>> a
23
>>> assert a == 23
>>> a -=1
>>> a
22
>>> assert a == 23

Traceback (most recent call last):
  File "", line 1, in
    assert a == 23
AssertionError
>>>

posted @ 2014-12-16 18:06  jane0912  阅读(1417)  评论(0编辑  收藏  举报