【python系统学习10】布尔值

2019/04/10 10:10
阅读数 33

<section id="nice" data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="font-size: 16px; color: black; padding: 10px; line-height: 1.6; word-spacing: 0px; letter-spacing: 0px; word-break: break-word; word-wrap: break-word; text-align: left; font-family: PingFangSC-Light;"><p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">python的数据类型有好多个,前边写过字符串、整数和浮点数这三种。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">本节来整理另一种简单数据类型--布尔值</p> <h2 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 24px; text-align: left; margin: 20px 10px 0px 0px;"><span style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid #ff5722;">布尔值(bool)</span></h2> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">布尔值和其数据值</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">计算机可以用数据进行判断,若判断为真则执行特定条件中的代码块。若不为真则执行相反的指定条件内的代码块或不执行任何内容。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">这种数据就是<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">布尔值</code>。其数据类型在python中标记为<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">bool</code>。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">布尔值其值比较特殊,不像字符串、整数那些,是用户自定的、无固定值的。他有固定的值,且只有两个:<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">True</code>、<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">False</code>(⚠️首字母大写)。</p> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">示例代码</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">下列代码分别打印<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">True</code>和<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">False</code></p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;">print(<span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>&gt;<span class="hljs-number" style="color: #008080; line-height: 26px;">1</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># True</span><br><br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>&lt;<span class="hljs-number" style="color: #008080; line-height: 26px;">1</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># False</span><br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">其中,<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">True表示真</code>,说明<strong style="font-weight: border; color: #ff5722;">条件成立</strong>。正如上例中,数字3是大于1的,判断的结果为“真”</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">相反,<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">False表示假</code>,说明<strong style="font-weight: border; color: #ff5722;">条件不成立</strong>。正如上例中,数字3不小于1,判断的结果为“假”</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">而<strong style="font-weight: border; color: #ff5722;">只有当条件判断为True(即条件成立)时,if和while后面的子句才会执行下去</strong>。<br> 比如下边的代码</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">True</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'这句话肯定会被执行'</span>)<br><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'这句话肯定不会被执行'</span>)<br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;"><strong style="font-weight: border; color: #ff5722;">⚠️特别的,在使用while时,如果当条件永远正确,那么就会出现循环一直执行停不下来、造成死循环现象</strong>。如下边的代码(千万不要轻易运行)</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">while</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">3</span> &gt; <span class="hljs-number" style="color: #008080; line-height: 26px;">1</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'糟了,是死循环的感觉!'</span>) <br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">3&gt;1</code>的判断永远成立,得到True后,while一直执行出现死循环。</p> <h2 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 24px; text-align: left; margin: 20px 10px 0px 0px;"><span style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid #ff5722;">布尔运算</span></h2> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">什么是布尔运算</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">根据布尔值数据所做的逻辑判断,叫做<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">布尔运算</code>。<br> 下例中,<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">3&gt;1</code>就是布尔运算。</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;">print(<span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>&gt;<span class="hljs-number" style="color: #008080; line-height: 26px;">1</span>)<br></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">布尔运算产生布尔值</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">试想一下,为什么我们这么写,if条件就执行了呢?</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">5</span> &gt; <span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'布尔运算产生布尔值'</span>)<br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">if语句后边条件判断语句需要一个布尔值,来指定判断后的逻辑,如果判断为真,则将执行if后的代码块。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">计算机会先做一次布尔运算,判断5是否大于3。判断结果是<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">5&gt;3</code>这个布尔运算返回了布尔值——<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">True</code>,条件成立if语句运行。</p> <h2 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 24px; text-align: left; margin: 20px 10px 0px 0px;"><span style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid #ff5722;">布尔运算的三种方式</span></h2> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">数值比较 - 比较运算符<br> 数值运算 - 真假判断<br> 布尔值运算 - 逻辑运算符</p> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">数值比较 - 比较运算符</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">python中的比较运算符</p> <table data-tool="mdnice编辑器" style="display: table; text-align: left;"> <thead> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">比较运算符</th> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">含义</th> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">备注</th> </tr> </thead> <tbody style="border: 0;"> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">等于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">==</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">判断数据和类型</td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">不等于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">!=</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">英文感叹号</td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">大于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">&gt;</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;"></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">小于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">&lt;</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;"></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">大于等于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">&gt;=</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;"></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">小于等于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">&lt;=</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;"></td> </tr> </tbody> </table> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">基本上就是小学数学!</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">::: tip ⚠️等于运算符(==) 1、需要两个等于号。<strong style="font-weight: border; color: #ff5722;">一个等于号(<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">=</code>)是赋值</strong>的作用<br> 2、不仅仅只判断左右两边的<strong style="font-weight: border; color: #ff5722;">值</strong>是否相等,还会判断符号左右的<strong style="font-weight: border; color: #ff5722;">数据类型</strong>是否一致。<br> 比如<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">print(3 == '3')</code>就会因为两边数据类型不一致,进而返回<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">False</code> :::</p> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">数值运算 - 真假判断</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">除了用数值比较作为语句的判断条件外,我们可以用一个数据/数值本身作为一个条件,直接进行真假判断。如下:</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-string" style="color: #d14; line-height: 26px;">'False'</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'这段你觉得会打印吗?'</span>)<br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">最后执行结果,就是打印了'这段你觉得会打印吗?'这句话。<br> 原因是,字符串'False'在这里就是作为一个条件,被判断为真(True)。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;"><strong style="font-weight: border; color: #ff5722;">在Python中被判定为假的数据是有限的</strong>,官方文档规定的。如下:</p> <h4 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 18px;"><span>python中的假值表</span></h4> <table data-tool="mdnice编辑器" style="display: table; text-align: left;"> <thead> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <th style="border: 1px solid #ccc; padding: 5px 10px; font-weight: bold; background-color: #f0f0f0; font-size: 14px; text-align: center;">序号</th> <th style="border: 1px solid #ccc; padding: 5px 10px; font-weight: bold; background-color: #f0f0f0; font-size: 14px; text-align: center;">认定为假的值</th> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">含义</th> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">备注</th> </tr> </thead> <tbody style="border: 0;"> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">1</td> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">False</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">布尔值中的<code>假</code></td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;"></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">2</td> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">0</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">整数<code>0</code></td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;"></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">3</td> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">None</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">数据类型<code>NoneType</code></td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;"></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">4</td> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">''</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">空字符串<code>空串</code></td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">里边有内容就为真 注意区别空串和空格字符串<code>‘ ’</code></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">5</td> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">[]</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">空列表</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">里边有内容就为真,如<code>[0]</code></td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">6</td> <td style="border: 1px solid #ccc; padding: 5px 10px; font-size: 14px; text-align: center;">{}</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">空字典</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">里边有内容就为真,如<code>{boolVal: Flase}</code></td> </tr> </tbody> </table> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">除了上述“假”值,其他值都会被判断为“真”。</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'False值为假,这句话不会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">0</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'整数0为假,这句话不会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'空值None为假,这句话不会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-string" style="color: #d14; line-height: 26px;">''</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'空串为假,这句话不会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> []:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'空列表为假,这句话不会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> {}:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'空字典为假,这句话不会被执行。'</span>)<br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">以上案例显示,各个数据本身作为一个条件时,会被判定为假,if后面的条件为假,计算机就都不会执行if的下一行代码。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">⚠️相反的,注意区分下边这些值,看上去和假值很像,但是他们都是<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">真</code></p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-string" style="color: #d14; line-height: 26px;">'False'</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'字符串"False"值为真,这句话会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-string" style="color: #d14; line-height: 26px;">'0'</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'字符串"0"值为真,这句话会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">-1</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'非0数字皆为真,这句话会被执行'</span>) <br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-string" style="color: #d14; line-height: 26px;">'None'</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'字符串"None"为真,这句话会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-string" style="color: #d14; line-height: 26px;">' '</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'空格字符串,不是空串!特别注意。空格字符串是真,这句话会被执行。'</span>)<br><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 可见,只要字符串不为空串,都为真。</span><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> [<span class="hljs-number" style="color: #008080; line-height: 26px;">0</span>]:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'列表不为空,条件为真,这句话会被执行。'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> {<span class="hljs-string" style="color: #d14; line-height: 26px;">'boolVal'</span>: <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>}:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'字典不为空,条件为真,这句话会被执行。'</span>)<br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;"><strong style="font-weight: border; color: #ff5722;">⚠️特别注意。空格字符串不是空串!他的布尔值是真</strong></p> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">布尔值运算 - 逻辑运算符</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">逻辑运算符有以下五种运算:</p> <table data-tool="mdnice编辑器" style="display: table; text-align: left;"> <thead> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">运算符</th> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">含义</th> <th style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-weight: bold; background-color: #f0f0f0; font-size: 14px;">备注</th> </tr> </thead> <tbody style="border: 0;"> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">and</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">与</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">并且</td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">or</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">或</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">或者</td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">not</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">非</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">取反</td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: #F8F8F8;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">in</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">属于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">判断数据是否属于一个字典或列表</td> </tr> <tr style="border: 0; border-top: 1px solid #ccc; background-color: white;"> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">not in</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">不属于</td> <td style="border: 1px solid #ccc; padding: 5px 10px; text-align: left; font-size: 14px;">同上,取反。判断不属于</td> </tr> </tbody> </table> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">篇幅比较大,整理到下边一个大模块中。</p> <h2 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 24px; text-align: left; margin: 20px 10px 0px 0px;"><span style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid #ff5722;">逻辑运算符</span></h2> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">and - 与</span></h3> <h4 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 18px;"><span>and的计算逻辑</span></h4> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">我自己学习js的并且(<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">&amp;&amp;</code>)时总结的顺口溜,同样适用于python中的并且(<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">and</code>):</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 关于判断规则</span><br>真真才为真<br>有假不算他<br><br><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 关于返回结果</span><br>真真得末尾<br>遇假返回假<br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">解释:and左右的条件,都为真时,总的判断结果就为真。否则一旦左边或右边有假值,则整个结果都是假的。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">如果两边都是真值,返回结果为最后的那个真值。<br> 如果两边有假值,则返回第一个遇到的假值。</p> <h4 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 18px;"><span>and案例</span></h4> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 真真才为真 案例:</span><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">1</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">2</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'真真返回结果:'</span>,<span class="hljs-number" style="color: #008080; line-height: 26px;">1</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">2</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 真真返回结果: 2(返回最后的那个真值)</span><br><br><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 有假不算他 案例:</span><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">2</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'不成立'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">else</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'真假返回结果:'</span>,<span class="hljs-number" style="color: #008080; line-height: 26px;">2</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 真假返回结果: None(返回第一个遇到的假值)</span><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">0</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'条件不成立,这里不打印'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">else</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'假假返回结果:'</span>,<span class="hljs-number" style="color: #008080; line-height: 26px;">0</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 假假返回结果: 0(返回第一个遇到的假值)</span><br><br><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 两边表达式,左边有假,则返回结果是第一个假表达式的执行结果:</span><br>a = <span class="hljs-number" style="color: #008080; line-height: 26px;">1</span><br>b = <span class="hljs-number" style="color: #008080; line-height: 26px;">2</span><br>c = <span class="hljs-number" style="color: #008080; line-height: 26px;">3</span><br>d = <span class="hljs-number" style="color: #008080; line-height: 26px;">4</span><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> a &gt; b <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> c &lt; d:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'条件不成立'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">else</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'真假表达式返回结果:'</span>, a &gt; b <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">and</span> c &lt; d) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># False (a&gt;b的结果)</span><br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">and对价值是零容忍的,只要有假、立马判定为假,谁说都不好使!</p> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">or - 或</span></h3> <h4 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 18px;"><span>or的计算逻辑</span></h4> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">同样来一段我学习时的顺口溜:</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 关于判断规则</span><br>有真即为真<br>假假才算假<br><br><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 关于返回结果</span><br>有真返回真<br>假假返末尾<br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">解释:or左右的条件,只要有一个为真时,总的判断结果就为真。<br> 必须左、右两边都是假值时,整个结果才是假的。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">如果两边都是真值、或者两边其中一边有一个真值,则返回结果为第一个遇到的真值。 如果两边都是假值,则返回最后的那个假值。</p> <h4 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 18px;"><span>or的案例:</span></h4> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 有真即为真 案例:</span><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">1</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">2</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'真真返回结果:'</span>,<span class="hljs-number" style="color: #008080; line-height: 26px;">1</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">2</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 真真返回结果: 1(返回第一个遇到的真值)</span><br><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">2</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'真假返回结果:'</span>,<span class="hljs-number" style="color: #008080; line-height: 26px;">2</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 真假返回结果: 2(返回第一个遇到的真值)</span><br><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'真假返回结果:'</span>,<span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 真假返回结果: 3(返回第一个遇到的真值)</span><br><br><br><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 假假才算假 案例:</span><br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">if</span> <span class="hljs-number" style="color: #008080; line-height: 26px;">0</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'条件不成立,这里不打印'</span>)<br><span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">else</span>:<br> print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'假假返回结果:'</span>,<span class="hljs-number" style="color: #008080; line-height: 26px;">0</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">or</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 假假返回结果: False(返回最后的那个假值)</span><br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">可以想象成or是对假值的容忍度很高,不监测到最后一个都为假,她是不会死心并直接判断为假值的。</p> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">not - 非</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">not</code>表示<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">翻转</code>的意思。所谓取反,就是颠倒真假的意思。<br> not True就等于False,not False就等于True。</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;">print(<span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">not</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">True</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># False</span><br>print(<span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">not</span> <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># True</span><br></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">in - 属于</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;"><code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">in</code>用来判断一个元素是否在一堆数据之中 数据集合是列表的话,【in】和【not in】就可以用来判断变量在不在列表list里面(in在、not in不在)。<br> 数据集合是字典的话,【in】和【not in】就可以用来判断字典中是否存在某个【键】(in在、not in不在):</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;">myName = [<span class="hljs-string" style="color: #d14; line-height: 26px;">'小石头'</span>, <span class="hljs-string" style="color: #d14; line-height: 26px;">'xing.org1^'</span>, <span class="hljs-number" style="color: #008080; line-height: 26px;">181</span>, <span class="hljs-literal" style="color: #008080; line-height: 26px;">True</span>]<br>dictName = {<br> <span class="hljs-string" style="color: #d14; line-height: 26px;">'name'</span>: <span class="hljs-string" style="color: #d14; line-height: 26px;">'小石头'</span>,<br> <span class="hljs-string" style="color: #d14; line-height: 26px;">'age'</span>: <span class="hljs-number" style="color: #008080; line-height: 26px;">19</span>,<br> <span class="hljs-string" style="color: #d14; line-height: 26px;">'hobby'</span>: {<br> <span class="hljs-string" style="color: #d14; line-height: 26px;">'it'</span>: [<span class="hljs-string" style="color: #d14; line-height: 26px;">'css'</span>,<span class="hljs-string" style="color: #d14; line-height: 26px;">'js'</span>,<span class="hljs-string" style="color: #d14; line-height: 26px;">'python'</span>],<br> <span class="hljs-string" style="color: #d14; line-height: 26px;">'daily'</span>: [[<span class="hljs-string" style="color: #d14; line-height: 26px;">'music'</span>,<span class="hljs-string" style="color: #d14; line-height: 26px;">'tv'</span>],[<span class="hljs-string" style="color: #d14; line-height: 26px;">'apple'</span>,<span class="hljs-string" style="color: #d14; line-height: 26px;">'pear'</span>]],<br> <span class="hljs-string" style="color: #d14; line-height: 26px;">'sports'</span>: <span class="hljs-string" style="color: #d14; line-height: 26px;">'sleep'</span><br> }<br>}<br><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'小石头'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> myName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># True 该字符串存在于列表中</span><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'gjf'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> myName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># False</span><br><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'hobby'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> dictName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># True</span><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'sex'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> dictName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># False</span><br></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">not in - 不属于</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">与<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">in</code>相反,用来判断一个元素是否不在一堆数据之中</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 变量沿用in案例中的</span><br><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'小石头'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> myName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># False 该字符串存在于列表中,非要说不在那是错误的,返回假值。</span><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'gjf'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> myName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># True</span><br><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'hobby'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> dictName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># False</span><br>print(<span class="hljs-string" style="color: #d14; line-height: 26px;">'sex'</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">not</span> <span class="hljs-keyword" style="color: #333; font-weight: bold; line-height: 26px;">in</span> dictName) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># True</span><br></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">优先级</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">三者之间的优先级:() &gt; not &gt; and &gt; or</p> <h2 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 24px; text-align: left; margin: 20px 10px 0px 0px;"><span style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid #ff5722;">类型查询 type()</span></h2> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;"><a href="http://localhost:8080/xingorg1Note/backEnd/python/02-dataType.html" style="text-decoration: none; word-wrap: break-word; font-weight: bold; color: #ff5722; border-bottom: 1px solid #ff3502; font-family: STHeitiSC-Light;">数据类型和类型转换</a>章节,提过type函数,他主要用于类型查询。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">布尔类型作为数据类型中的一种,同样可以用type函数进行类型查询:</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;">print(type(<span class="hljs-literal" style="color: #008080; line-height: 26px;">True</span>)) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># &lt;class 'bool'&gt;</span><br><br>print(type(<span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>)) <span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># &lt;class 'bool'&gt;</span><br></code></pre> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">可以从打印结果看出来,布尔值的类型返回为<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">&lt;class 'bool'&gt;</code>。</p> <h2 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 24px; text-align: left; margin: 20px 10px 0px 0px;"><span style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid #ff5722;">布尔值判断 bool()</span></h2> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">虽然我们有<a href="#python%E4%B8%AD%E7%9A%84%E5%81%87%E5%80%BC%E8%A1%A8" style="text-decoration: none; word-wrap: break-word; font-weight: bold; color: #ff5722; border-bottom: 1px solid #ff3502; font-family: STHeitiSC-Light;">python中的假值表</a>, 肉眼就能辨别真假值。</p> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">不过python也提供了<code style="font-size: 14px; word-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin: 0 2px; background-color: rgba(27,31,35,.05); font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; word-break: break-all; color: rgb(271,93,108);">bool()</code>函数来帮助我们判断数据的真假。下边是使用案例:</p> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">以下皆打印False</span></h3> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;">print(<span class="hljs-number" style="color: #008080; line-height: 26px;">1</span>, bool(<span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">2</span>, bool(<span class="hljs-number" style="color: #008080; line-height: 26px;">0</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>, bool(<span class="hljs-string" style="color: #d14; line-height: 26px;">''</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">4</span>, bool(<span class="hljs-literal" style="color: #008080; line-height: 26px;">None</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">5</span>, bool([]))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">6</span>, bool({}))<br></code></pre> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">以下皆返回True</span></h3> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;">print(<span class="hljs-number" style="color: #008080; line-height: 26px;">1</span>, bool(<span class="hljs-string" style="color: #d14; line-height: 26px;">'False'</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">2</span>, bool(<span class="hljs-string" style="color: #d14; line-height: 26px;">'0'</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">3</span>, bool(<span class="hljs-string" style="color: #d14; line-height: 26px;">' '</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">4</span>, bool(<span class="hljs-string" style="color: #d14; line-height: 26px;">'None'</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">5</span>, bool([<span class="hljs-number" style="color: #008080; line-height: 26px;">0</span>]))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">6</span>, bool({<span class="hljs-string" style="color: #d14; line-height: 26px;">'boolVal'</span>: <span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>}))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">7</span>, bool(<span class="hljs-string" style="color: #d14; line-height: 26px;">'字符串除了空串都为真'</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">8</span>, bool(<span class="hljs-number" style="color: #008080; line-height: 26px;">-1</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">9</span>, bool(<span class="hljs-number" style="color: #008080; line-height: 26px;">1.3</span>))<br>print(<span class="hljs-number" style="color: #008080; line-height: 26px;">10</span>, bool([<span class="hljs-literal" style="color: #008080; line-height: 26px;">False</span>]))<br></code></pre> <h2 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 24px; text-align: left; margin: 20px 10px 0px 0px;"><span style="font-family: STHeitiSC-Light; font-size: 18px; font-weight: bolder; display: inline-block; padding-left: 10px; border-left: 5px solid #ff5722;">思考题</span></h2> <h3 data-tool="mdnice编辑器" style="margin-top: 40px; margin-bottom: 20px; font-weight: bold; color: black; font-size: 20px;"><span style="font-size: 14px; color: #ff5722;">一百遍“我真棒”</span></h3> <p data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em;">用布尔运算实现while循环重复执行100遍打印“我真棒”的任务</p> <pre class="custom" data-tool="mdnice编辑器" style="margin-top: 10px; margin-bottom: 10px;"><code class="hljs" style="overflow-x: auto; padding: 16px; color: #333; background: #f8f8f8; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; border-radius: 8px;"><span class="hljs-comment" style="color: #998; font-style: italic; line-height: 26px;"># 参考代码位于源代码files文件夹下对应章节的py文件中</span><br></code></pre> <p id="nice-suffix-juejin-container" class="nice-suffix-juejin-container" data-tool="mdnice编辑器" style="padding-top: 8px; padding-bottom: 8px; color: black; margin: 10px 10px; line-height: 1.75; letter-spacing: 0.2em; font-size: 14px; word-spacing: 0.1em; margin-top: 20px !important;">本文使用 <a href="https://mdnice.com" style="text-decoration: none; word-wrap: break-word; font-weight: bold; color: #ff5722; border-bottom: 1px solid #ff3502; font-family: STHeitiSC-Light;">mdnice</a> 排版</p></section>

原文出处:https://www.cnblogs.com/padding1015/p/12499572.html

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部