您的位置:首页 > 编程语言 > Python开发

Python assert 用法

2017-04-20 21:54 471 查看
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:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: