码迷,mamicode.com
首页 > 编程语言 > 详细

assert函数(python)

时间:2014-09-15 19:16:59      阅读:599      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   div   sp   log   on   

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

 

assert函数(python)

标签:style   blog   color   io   os   div   sp   log   on   

原文地址:http://www.cnblogs.com/fei-hsueh/p/3973280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!