⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch15s07.html

📁 《简明 Python 教程》为 "A Byte of Python" 的唯一指定简体中文译本
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css"><!--@import url(stylesheet/text.css);@import url(stylesheet/box.css);--></style><title>简明 Python 教程 / 更多Python的内容 / assert语句 </title></head><body><table width="100%"><tr><th colspan="3" align="center"><span class="header">简明 Python 教程</span></th></tr><th colspan="3" align="center">第15章 更多Python的内容</th><tr><th width="20%" align="left"><a href="ch15s06.html">上一页</a></th><th width="60%" align="center"><span class="header2">assert语句</span></th><th align="right"><a href="ch15s08.html">下一页</a></th></tr></table><hr noshade><h1>assert语句</h1><p><code>assert</code>语句用来声明某个条件是真的。例如,如果你非常确信某个你使用的列表中至少有一个元素,而你想要检验这一点,并且在它非真的时候引发一个错误,那么<code>assert</code>语句是应用在这种情形下的理想语句。当assert语句失败的时候,会引发一个<code>AssertionError</code>。</p><p class="codebox"><code>&gt;&gt;&gt; mylist = ['item']<br>&gt;&gt;&gt; assert len(mylist) &gt;= 1<br>&gt;&gt;&gt; mylist.pop()<br>'item'<br>&gt;&gt;&gt; assert len(mylist) &gt;= 1<br>Traceback (most recent call last):<br>&nbsp;&nbsp;File "&lt;stdin&gt;", line 1, in ?<br>AssertionError</code></p><hr noshade><table width="100%"><tr><th width="20%" align="left"><a href="ch15s06.html">上一页</a></th><th width="60%" align="center"><a href="ch15.html">上一级</a></th><th width="20%" align="right"><a href="ch15s08.html">下一页</a></th></tr><tr><th width="20%" align="left">exec和eval语句</th><th width="60%" align="center"><a href="index.html">首页</a></th><th align="right">repr函数</th></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -