python assert用法
2013-10-31 17:14
399 查看
1、assert语句用来声明某个条件是真的。
2、如果你非常确信某个你使用的列表中至少有一个元素,而你想要检验这一点,并且在它非真的时候引发一个错误,那么
assert语句是应用在这种情形下的理想语句。
3、当assert语句失败的时候,会引发一
AssertionError。
>>> mylist = ['qqqqqq']
>>> assert len(mylist) >=1
>>> mylist.pop()
'qqqqqq'
>>> mylist
[]
>>> assert len(mylist) >=1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
>>> len(mylist) >=1
False
相关文章推荐
- Python中assert的用法
- python assert 断言详细用法格式
- python assert 断言基本用法
- Python assert断言异常语句格式及用法
- python assert 断言详细用法格式
- python中assert用法实例分析
- Python语言assert用法
- python assert用法
- python3 assert 断言的用法 (区别于python2)
- python中小用法之assert,*arg,**arg用法全解
- Python-assert的用法
- Python进阶---python assert用法
- 【转】python assert用法
- Python 3 小知识 assert用法
- Python基础学习篇—assert用法
- python中assert断言的用法
- python中assert用法实例分析
- python assert断言的用法
- python中assert、isinstance的用法
- assert 用法及获取IP 分类: python基础学习 2013-07-24 16:54 344人阅读 评论(0) 收藏