Python中assert的用法

来源:互联网 发布:mac中的照片怎么导出 编辑:程序博客网 时间:2024/05/16 09:51

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
>>>

0 0
原创粉丝点击