马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Python assert 语句
语法:
assert expression [, argument]
[size]栗子:
>>> assert True
>>> assert False # 会报错
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
assert False # 会报错
AssertionError
>>> a = 0
>>> assert a
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
assert a
AssertionError
>>> assert (5 == 5)
>>> a = 'q'
>>> assert (a in 'qiuyouzhi'), "错误!"
>>> a = 'f'
>>> assert (a in 'qiuyouzhi'), "错误!"
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
assert (a in 'qiuyouzhi'), "错误!"
AssertionError: 错误!
|