assert函数(python)

assert语句:

用以检查某一条件是否为True,若该条件为False则会给出一个AssertionError。

用法:

assert type(x)=int and x>=0

如果不满足后面的expression,则会弹出

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    assert type(n)==int and n>0
AssertionError

 

posted @ 2014-09-15 17:33  ivyxjc  阅读(8473)  评论(0编辑  收藏  举报