Assert-info
Assert 断言函数
简介:
assert expression [, arguments]
用法:
>>assert 1==1
>> assert 1 == 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
>>assert 2+2==2*2
>>assert len(['my boy',12])<10
>>assert range(4)==[0,1,2,3]
>>> mylist = ['item']
>>assert len(mylist) >= 1
>>mylist.pop()
'item'
>>assert len(mylist) >= 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError使用误区:
1. 以assert方式作为参数异常
2.适用情形
3.以断言代替不必要注释
Last updated