Python assert 用法

来源:互联网 发布:网络赌托该不该举报 编辑:程序博客网 时间:2024/06/12 00:29

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

python help document的解释:

Assert statements are a convenient way to insert debugging assertions into a program:

例:

>>> a = 3
>>> assert a ==3
>>> a = 2
>>> assert a ==3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError

例2:



0 0