{"id":68,"date":"2026-08-05T23:47:55","date_gmt":"2026-08-05T15:47:55","guid":{"rendered":"https:\/\/ltrainyard.icu\/?p=68"},"modified":"2026-08-06T00:42:17","modified_gmt":"2026-08-05T16:42:17","slug":"day-4-%e6%9d%a1%e4%bb%b6%e5%88%a4%e6%96%ad%ef%bc%9a%e5%b8%83%e5%b0%94%e5%80%bc%e4%b8%8e-if-elif-else","status":"publish","type":"post","link":"https:\/\/ltrainyard.icu\/index.php\/2026\/08\/05\/day-4-%e6%9d%a1%e4%bb%b6%e5%88%a4%e6%96%ad%ef%bc%9a%e5%b8%83%e5%b0%94%e5%80%bc%e4%b8%8e-if-elif-else\/","title":{"rendered":"| Day 4 | \u6761\u4ef6\u5224\u65ad\uff1a\u5e03\u5c14\u503c\u4e0e if \/ elif \/ else |"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1 \u5e03\u5c14\u503c \u2014\u2014 \u7a0b\u5e8f\u5224\u65ad\u7684\u300c\u5f00\u5173\u300d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e03\u5c14\u503c<\/strong>\uff08bool\uff09\u53ea\u6709\u4e24\u4e2a\uff1a<code>True<\/code>\uff08\u771f\uff09\u548c <code>False<\/code>\uff08\u5047\uff09\u3002\u800c<strong>\u6761\u4ef6\u8868\u8fbe\u5f0f<\/strong>\u5c31\u662f\u300c\u4f1a\u7b97\u51fa\u4e00\u4e2a\u5e03\u5c14\u503c\u7684\u5f0f\u5b50\u300d\u2014\u2014\u6bd4\u5982 <code>5 &gt; 3<\/code> \u95ee\u300c5 \u5927\u4e8e 3 \u5417\uff1f\u300d\uff0c\u7b97\u51fa\u6765\u662f <code>True<\/code>\u3002\u4e3a\u4ec0\u4e48\u96f6\u57fa\u7840\u5fc5\u5b66\uff1f\u56e0\u4e3a if \u5224\u65ad\u7684\u300c\u5f00\u5173\u300d\u5c31\u662f\u5e03\u5c14\u503c\uff1a<strong>\u6761\u4ef6\u7b97\u51fa True \u5c31\u8d70\u8fd9\u6761\u8def\uff0c\u7b97\u51fa False \u5c31\u8d70\u53e6\u4e00\u6761<\/strong>\u3002\u5148\u628a\u5f00\u5173\u8ba4\u8bc6\u6e05\u695a\uff0cif \u5c31\u53ea\u5269\u5957\u7528\u683c\u5f0f\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08<code>&gt; &lt; == != &gt;= &lt;=<\/code>\uff09\u7684\u672c\u8d28\u662f\u300c\u63d0\u95ee\u300d\uff0cPython \u7b97\u51fa\u7b54\u6848\u540e\u8fd4\u56de\u5e03\u5c14\u503c\u3002\u4e24\u4e2a\u7ec6\u8282\u5e2e\u52a9\u4f60\u7406\u89e3\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5e03\u5c14\u503c\u5728\u5e95\u5c42\u662f\u7279\u6b8a\u7684\u6574\u6570\uff1a<code>True<\/code> \u7b49\u4ef7\u4e8e 1\uff0c<code>False<\/code> \u7b49\u4ef7\u4e8e 0\uff08\u8fd9\u4e5f\u662f <code>if 1:<\/code> \u80fd\u6210\u7acb\u7684\u539f\u56e0\uff0c\u4f46<strong>\u5b9e\u9645\u4ee3\u7801\u4e0d\u8981\u4f9d\u8d56\u5b83<\/strong>\uff09\u3002<\/li>\n\n\n\n<li>\u5b57\u7b26\u4e32\u4e5f\u80fd\u6bd4\u8f83\uff08\u6309\u5b57\u6bcd\/\u5b57\u5178\u987a\u5e8f\uff09\uff0c<code>\"abc\" &lt; \"abd\"<\/code> \u662f True\u2014\u2014\u6240\u4ee5\u5224\u65ad\u4e0d\u9650\u4e8e\u6570\u5b57\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e03\u5c14\u503c\u50cf<strong>\u6295\u7968\u6309\u94ae<\/strong>\uff1a\u6bcf\u4e2a\u6309\u94ae\u53ea\u6709\u300c\u8d5e\u6210\uff08True\uff09\u300d\u548c\u300c\u53cd\u5bf9\uff08False\uff09\u300d\u4e24\u4e2a\u9009\u9879\uff0c\u6ca1\u6709\u7b2c\u4e09\u79cd\u3002\u6761\u4ef6\u8868\u8fbe\u5f0f\u5c31\u662f\u300c\u7a0b\u5e8f\u5728\u6295\u7968\u300d\u2014\u2014<code>5 &gt; 3<\/code> \u6295\u4e86\u8d5e\u6210\u7968\uff08True\uff09\uff0c<code>5 &lt; 3<\/code> \u6295\u4e86\u53cd\u5bf9\u7968\uff08False\uff09\u3002if \u8bed\u53e5\u5219\u662f\u770b\u7968\u7ed3\u679c\u51b3\u5b9a\u8d70\u54ea\u6247\u95e8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u6761\u4ef6\u8868\u8fbe\u5f0f\u7b97\u51fa\u6765\u662f\u5e03\u5c14\u503c<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(10 &gt; 5)        # True\uff1a10 \u5927\u4e8e 5 \u6210\u7acb\nprint(10 &lt; 5)        # False\uff1a10 \u5c0f\u4e8e 5 \u4e0d\u6210\u7acb\nprint(10 == 10)      # True\uff1a\u76f8\u7b49\u5224\u65ad\u6210\u7acb\nprint(10 != 10)      # False\uff1a\u4e0d\u76f8\u7b49\u5224\u65ad\u4e0d\u6210\u7acb\nprint(\"abc\" == \"abc\")  # True\uff1a\u5b57\u7b26\u4e32\u4e5f\u53ef\u4ee5\u6bd4\u8f83\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>True\nFalse\nTrue\nFalse\nTrue\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u628a\u6bd4\u8f83\u7ed3\u679c\u5b58\u8fdb\u53d8\u91cf<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>age = 18\nis_adult = age &gt;= 18    # \u5148\u628a\u300c\u662f\u5426\u6210\u5e74\u300d\u7684\u7ed3\u679c\u5b58\u8d77\u6765\nprint(is_adult)         # True\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53d8\u91cf\u4e0d\u4ec5\u80fd\u5b58\u6570\u5b57\u3001\u6587\u672c\uff0c\u4e5f\u80fd\u5b58\u5e03\u5c14\u503c\u2014\u2014\u4e4b\u540e\u53ef\u4ee5\u76f4\u63a5\u7528 <code>is_adult<\/code> \u505a\u5224\u65ad\uff0c\u4ee3\u7801\u66f4\u597d\u8bfb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>if age = 18:<\/code>\uff08\u4e00\u4e2a\u7b49\u53f7\uff09 \u2192 \u95ee\u9898\uff1a<code>=<\/code> \u662f\u8d4b\u503c\u4e0d\u662f\u5224\u65ad\uff0c\u8bed\u6cd5\u9519\u8bef \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>if age == 18:<\/code> \u4e24\u4e2a\u7b49\u53f7\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>print(\"18\" == 18)<\/code> \u4ee5\u4e3a\u7ed3\u679c\u662f True \u2192 \u95ee\u9898\uff1a\u5b57\u7b26\u4e32\u548c\u6574\u6570\u6c38\u8fdc\u4e0d\u76f8\u7b49\uff0c\u7ed3\u679c\u662f False \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148\u8f6c\u6362\uff1a<code>int(\"18\") == 18<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>is_ok = yes<\/code> \u2192 \u95ee\u9898\uff1a<code>yes<\/code> \u4e0d\u662f Python \u8ba4\u8bc6\u7684\u8bcd\uff0c\u62a5 <code>NameError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5e03\u5c14\u503c\u53ea\u6709 <code>True<\/code> \/ <code>False<\/code>\uff08\u9996\u5b57\u6bcd\u5927\u5199\uff09\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>if x == True:<\/code> \u5224\u65ad\u300cx \u4e3a\u771f\u300d \u2192 \u95ee\u9898\uff1a\u80fd\u8fd0\u884c\u4f46\u5570\u55e6\uff0c\u4e14\u7c7b\u578b\u8f6c\u6362\u5bb9\u6613\u51fa bug \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u76f4\u63a5 <code>if x:<\/code>\uff08x \u4e3a\u771f\u65f6\u6267\u884c\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u6bd4\u8f83\u51fa\u5e03\u5c14\uff0cTrue \u771f False \u5047\uff1b\u5224\u65ad\u7528\u53cc\u7b49\uff0c\u8d4b\u503c\u7528\u5355\u7b49\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2 if \u8bed\u53e5 \u2014\u2014 \u6761\u4ef6\u6210\u7acb\u624d\u6267\u884c<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>if<\/code> \u7ffb\u8bd1\u8fc7\u6765\u662f\u300c\u5982\u679c\u300d\uff1a<strong>\u6761\u4ef6\u6210\u7acb\uff08True\uff09\uff0c\u5c31\u6267\u884c\u4e0b\u9762\u7f29\u8fdb\u7684\u4ee3\u7801\uff1b\u4e0d\u6210\u7acb\uff08False\uff09\uff0c\u5c31\u8df3\u8fc7<\/strong>\u3002\u4e3a\u4ec0\u4e48\u96f6\u57fa\u7840\u5fc5\u5b66\uff1f\u56e0\u4e3a\u5b83\u662f\u7a0b\u5e8f\u300c\u5206\u5c94\u8def\u53e3\u300d\u7684\u7b2c\u4e00\u5757\u8def\u724c\u2014\u2014\u6ca1\u6709 if\uff0c\u7a0b\u5e8f\u53ea\u80fd\u4e00\u6761\u8def\u8d70\u5230\u9ed1\uff1b\u6709\u4e86 if\uff0c\u7a0b\u5e8f\u624d\u80fd\u771f\u6b63\u300c\u505a\u51b3\u5b9a\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u5224\u65ad\u300c\u54ea\u4e9b\u4ee3\u7801\u5c5e\u4e8e if\u300d\u9760\u7684\u662f<strong>\u7f29\u8fdb<\/strong>\uff08\u901a\u5e38 4 \u4e2a\u7a7a\u683c\u6216\u4e00\u4e2a Tab\uff09\uff0c\u800c\u4e0d\u662f\u50cf C\/Java \u90a3\u6837\u7528\u82b1\u62ec\u53f7 <code>{}<\/code>\u3002\u56e0\u4e3a Python \u7684\u8bbe\u8ba1\u54f2\u5b66\u662f\u300c\u53ef\u8bfb\u6027\u4f18\u5148\u300d\u2014\u2014\u5f3a\u5236\u7f29\u8fdb\u8ba9\u4ee3\u7801\u7ed3\u6784\u4e00\u773c\u53ef\u89c1\uff0c\u4e0d\u4f1a\u51fa\u73b0\u300c\u82b1\u62ec\u53f7\u6ee1\u5929\u98de\u3001\u7ed3\u6784\u5168\u9760\u6570\u62ec\u53f7\u300d\u7684\u707e\u96be\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bed\u6cd5\u7ed3\u6784\u4e00\u53e5\u8bdd\u6982\u62ec\uff1a<code>if \u6761\u4ef6:<\/code> \u6362\u884c\u540e\uff0c<strong>\u7f29\u8fdb\u7684\u4ee3\u7801\u662f if \u7684\u9886\u5730\uff08\u6210\u7acb\u624d\u6267\u884c\uff09\uff0c\u6ca1\u7f29\u8fdb\u7684\u4ee3\u7801\u4e0d\u53d7\u5f71\u54cd\uff08\u603b\u4f1a\u6267\u884c\uff09<\/strong>\u3002\u5c0f\u7ed3\u4e09\u70b9\uff1a\u2460 \u6761\u4ef6\u540e\u9762\u5fc5\u987b\u6709<strong>\u5192\u53f7<\/strong> <code>:<\/code>\uff1b\u2461 \u7f29\u8fdb\u7684\u4ee3\u7801\u662f\u4e00\u6574\u5757\uff0c\u8981\u6267\u884c\u4e00\u8d77\u6267\u884c\u3001\u8981\u8df3\u8fc7\u4e00\u8d77\u8df3\u8fc7\uff1b\u2462 \u5192\u53f7\u548c\u7f29\u8fdb\u7f3a\u4e00\u4e0d\u53ef\uff0c\u5426\u5219\u62a5 <code>SyntaxError<\/code> \/ <code>IndentationError<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if \u50cf<strong>\u95e8\u7981\u5237\u5361<\/strong>\uff1a\u5237\u5361\u6210\u529f\uff08\u6761\u4ef6\u4e3a True\uff09\uff0c\u95e8\u6253\u5f00\u3001\u4f60\u8d70\u8fdb\u53bb\uff08\u7f29\u8fdb\u7684\u4ee3\u7801\u6267\u884c\uff09\uff1b\u5237\u5361\u5931\u8d25\uff08\u6761\u4ef6\u4e3a False\uff09\uff0c\u95e8\u4e0d\u5f00\uff0c\u4f60\u7ad9\u5728\u95e8\u53e3\u2014\u2014\u4f46<strong>\u6ca1\u5237\u5361\u7684\u4eba\uff08\u6ca1\u7f29\u8fdb\u7684\u4ee3\u7801\uff09\u4e0d\u53d7\u5f71\u54cd<\/strong>\uff0c\u7167\u5e38\u5728\u5927\u5385\u8d70\u52a8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>if \u7684\u7ed3\u6784\u6f14\u793a<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score = 60\nif score &gt;= 60:                      # \u6761\u4ef6 + \u5192\u53f7\n    print(\"\u6761\u4ef6\u6210\u7acb\uff0c\u7f29\u8fdb\u4ee3\u7801\u6267\u884c\")    # \u7f29\u8fdb\u4ee3\u7801 1\uff1a\u5c5e\u4e8e if\n    print(\"\u7f29\u8fdb\u7684\u4ee3\u7801 2\")             # \u7f29\u8fdb\u4ee3\u7801 2\uff1a\u540c\u6837\u5c5e\u4e8e if\nprint(\"\u6ca1\u7f29\u8fdb\u7684\u4ee3\u7801\uff1a\u6bcf\u6b21\u90fd\u4f1a\u6267\u884c\")     # \u6ca1\u7f29\u8fdb\uff1a\u4e0d\u53d7 if \u63a7\u5236\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6761\u4ef6\u6210\u7acb\uff0c\u7f29\u8fdb\u4ee3\u7801\u6267\u884c\n\u7f29\u8fdb\u7684\u4ee3\u7801 2\n\u6ca1\u7f29\u8fdb\u7684\u4ee3\u7801\uff1a\u6bcf\u6b21\u90fd\u4f1a\u6267\u884c\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7f29\u8fdb\u76f8\u540c = \u540c\u5c5e\u4e00\u5757<\/strong>\uff0c\u8fd9\u662f Python \u4ee3\u7801\u5757\u7684\u94c1\u5f8b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u6761\u4ef6\u4e3a\u5047\u65f6\u7f29\u8fdb\u4ee3\u7801\u88ab\u8df3\u8fc7<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score = 50\nif score &gt;= 60:\n    print(\"\u53ca\u683c\u4e86\uff01\")      # \u4e0d\u4f1a\u6267\u884c\nprint(\"\u8fd9\u53e5\u8bdd\u6bcf\u6b21\u90fd\u6267\u884c\")   # \u6ca1\u6709\u7f29\u8fdb\uff0c\u4e0d\u53d7 if \u63a7\u5236\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u8fd9\u53e5\u8bdd\u6bcf\u6b21\u90fd\u6267\u884c\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u540c\u6837\u7684\u4ee3\u7801\u53ea\u662f\u5206\u6570\u4e0d\u540c\uff0c\u884c\u4e3a\u5c31\u4e0d\u540c\u2014\u2014\u8fd9\u5c31\u662f\u300c\u6761\u4ef6\u5224\u65ad\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>if score >= 60<\/code>\uff08\u5fd8\u5199\u5192\u53f7\uff09 \u2192 \u95ee\u9898\uff1a\u62a5 <code>SyntaxError: invalid syntax<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>if score >= 60:<\/code> \u5192\u53f7\u5fc5\u5e26\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1aif \u4e0b\u9762\u9876\u683c\u5199 <code>print(\"\u53ca\u683c\u4e86\")<\/code>\uff08\u5fd8\u7f29\u8fdb\uff09 \u2192 \u95ee\u9898\uff1a\u62a5 <code>IndentationError: expected an indented block<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1aif \u7684\u4e0b\u4e00\u884c\u5148\u7f29\u8fdb\uff084 \u4e2a\u7a7a\u683c\u6216\u4e00\u4e2a Tab\uff09\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u7f29\u8fdb\u6df7\u7528 Tab \u548c\u7a7a\u683c \u2192 \u95ee\u9898\uff1a\u770b\u7740\u5bf9\u9f50\uff0cPython \u62a5 <code>IndentationError: unexpected indent<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5168\u9879\u76ee\u7edf\u4e00\u7528 4 \u4e2a\u7a7a\u683c\uff08VS Code \u9ed8\u8ba4\u914d\u7f6e\u5373\u53ef\uff09\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u628a\u300c\u603b\u4f1a\u6267\u884c\u7684\u4ee3\u7801\u300d\u4e5f\u7f29\u8fdb\u4e86 \u2192 \u95ee\u9898\uff1a\u5b83\u88ab\u8bef\u5224\u6210 if \u7684\u4e00\u90e8\u5206\uff0c\u6761\u4ef6\u4e3a\u5047\u65f6\u4e0d\u4f1a\u6267\u884c \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148\u60f3\u6e05\u695a\u2014\u2014\u53ea\u6709\u300c\u6761\u4ef6\u6210\u7acb\u624d\u8be5\u6267\u884c\u7684\u300d\u624d\u7f29\u8fdb\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1aif \u540e\u9762\u5e26\u5192\u53f7\uff0c\u7f29\u8fdb\u4ee3\u7801\u5f52\u5b83\u7ba1\uff1b\u6761\u4ef6\u4e3a\u771f\u624d\u6267\u884c\uff0c\u4e3a\u5047\u6574\u5757\u9760\u8fb9\u7ad9\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3 if \/ else \u2014\u2014 \u4e8c\u9009\u4e00<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>else<\/code> \u7ffb\u8bd1\u8fc7\u6765\u662f\u300c\u5426\u5219\u300d\uff1a<strong>if \u7684\u6761\u4ef6\u4e0d\u6210\u7acb\u65f6\uff0c\u6267\u884c else \u4e0b\u9762\u7684\u4ee3\u7801<\/strong>\u3002if \/ else \u7ec4\u5408\u5c31\u662f\u300c\u4e8c\u9009\u4e00\u300d\u2014\u2014\u751f\u6d3b\u4e2d\u7684\u53ca\u683c\/\u4e0d\u53ca\u683c\u3001\u901a\u8fc7\/\u672a\u901a\u8fc7\u3001\u767d\u5929\/\u9ed1\u591c\uff0c\u5168\u662f\u4e8c\u9009\u4e00\u3002\u4e3a\u4ec0\u4e48\u5fc5\u5b66\uff1f\u56e0\u4e3a\u5b83\u662f\u6761\u4ef6\u5224\u65ad\u7684\u57fa\u672c\u76d8\uff0c\u628a\u300c\u662f\/\u5426\u300d\u4e24\u7c7b\u60c5\u51b5\u90fd\u7167\u987e\u5230\uff0c\u7a0b\u5e8f\u624d\u4e0d\u4f1a\u300c\u6f0f\u6389\u53e6\u4e00\u534a\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if \/ else \u662f\u4e00\u5bf9\u300c\u4e92\u8865\u5757\u300d\uff1a\u6761\u4ef6\u4e3a True \u8d70 if \u5757\uff0c\u4e3a False \u8d70 else \u5757\u2014\u2014<strong>\u4e24\u8005\u5fc5\u8d70\u5176\u4e00\uff0c\u4e14\u53ea\u8d70\u4e00\u4e2a<\/strong>\u3002\u6ce8\u610f else \u540e\u9762<strong>\u4e0d\u5199\u6761\u4ef6<\/strong>\u3001\u76f4\u63a5\u8ddf\u5192\u53f7\uff08<code>else:<\/code>\uff09\uff0c\u56e0\u4e3a\u5b83\u7684\u6761\u4ef6\u5c31\u662f\u300cif \u7684\u6761\u4ef6\u4e0d\u6210\u7acb\u300d\uff0cPython \u5df2\u7ecf\u77e5\u9053\u4e86\u3002else \u8981\u548c if <strong>\u5bf9\u9f50\u7f29\u8fdb<\/strong>\uff0c\u8868\u793a\u5b83\u4eec\u662f\u300c\u540c\u4e00\u5c42\u300d\u7684\u4e24\u4e2a\u5206\u652f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">if \/ else \u50cf<strong>\u5bbf\u820d\u95e8\u7981\u7684\u4e24\u79cd\u7ed3\u679c<\/strong>\uff1a\u5237\u5361\u6210\u529f\uff08if \u6761\u4ef6 True\uff09\u2192\u300c\u6b22\u8fce\u56de\u5bb6\u300d\uff1b\u5237\u5361\u5931\u8d25\uff08else\uff09\u2192\u300c\u8bf7\u91cd\u65b0\u5237\u5361\u300d\u3002\u95e8\u7981\u7cfb\u7edf\u53ea\u4f1a\u4e8c\u9009\u4e00\uff0c\u4e0d\u4f1a\u4e24\u4e2a\u90fd\u64ad\u62a5\uff0c\u4e5f\u4e0d\u4f1a\u90fd\u4e0d\u64ad\u62a5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u4e8c\u9009\u4e00<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score = 50\nif score &gt;= 60:\n    print(\"\u53ca\u683c\u4e86\uff01\")\nelse:\n    print(\"\u6ca1\u53ca\u683c\uff0c\u7ee7\u7eed\u52a0\u6cb9\uff01\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6ca1\u53ca\u683c\uff0c\u7ee7\u7eed\u52a0\u6cb9\uff01\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f else \u548c if <strong>\u9876\u683c\u5bf9\u9f50<\/strong>\uff0c\u4e14 else \u540e\u9762\u76f4\u63a5\u5192\u53f7\u3001\u6ca1\u6709\u6761\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u5224\u65ad\u5947\u5076<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>num = 7\nif num % 2 == 0:\n    print(num, \"\u662f\u5076\u6570\")\nelse:\n    print(num, \"\u662f\u5947\u6570\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>7 \u662f\u5947\u6570\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>num % 2<\/code> \u662f 7 \u00f7 2 \u7684\u4f59\u6570 1\uff0c<code>1 == 0<\/code> \u662f False\uff0c\u6240\u4ee5\u8d70 else\u2014\u2014\u4f59\u6570\u53ea\u6709 0\uff08\u5076\u6570\uff09\u548c 1\uff08\u5947\u6570\uff09\u4e24\u79cd\u53ef\u80fd\uff0c\u662f\u300c\u4e8c\u9009\u4e00\u300d\u7684\u7ecf\u5178\u5e94\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>else (score &lt; 60):<\/code> \u2192 \u95ee\u9898\uff1aelse \u540e\u9762\u4e0d\u80fd\u5199\u6761\u4ef6\uff0c\u62a5\u8bed\u6cd5\u9519\u8bef \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>else:<\/code> \u76f4\u63a5\u5192\u53f7\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1aelse \u548c if \u7f29\u8fdb\u4e0d\u4e00\u81f4 \u2192 \u95ee\u9898\uff1aPython \u627e\u4e0d\u5230 else \u5bf9\u5e94\u7684 if\uff0c\u62a5 <code>IndentationError<\/code> \/ <code>SyntaxError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1aelse \u4e0e if \u4e25\u683c\u5bf9\u9f50\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1aelse \u540e\u9762\u5fd8\u5199\u5192\u53f7 <code>else<\/code> \u2192 \u95ee\u9898\uff1a\u62a5 <code>SyntaxError: invalid syntax<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>else:<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u628a else \u4e5f\u7f29\u8fdb\u5230 if \u5757\u91cc\u9762 \u2192 \u95ee\u9898\uff1a\u53d8\u6210\u300cif \u6210\u7acb\u624d\u68c0\u67e5 else\u300d\uff0c\u903b\u8f91\u5b8c\u5168\u53d8\u5473 \u2192 \u6b63\u786e\u5199\u6cd5\uff1aelse \u4e0e if \u5e73\u7ea7\u5bf9\u9f50\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1aif \u4e0d\u884c else \u4e0a\uff0c\u4e24\u8005\u53ea\u8d70\u4e00\u6761\u9053\uff1belse \u540e\u9762\u6ca1\u6761\u4ef6\uff0c\u9876\u683c\u5bf9\u9f50\u522b\u5fd8\u4e86\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4 if \/ elif \/ else \u2014\u2014 \u591a\u9009\u4e00\u4e0e\u6761\u4ef6\u7684\u987a\u5e8f<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e8b\u60c5\u4e0d\u6b62\u4e24\u79cd\u7ed3\u679c\u600e\u4e48\u529e\uff1f\u6bd4\u5982\u6210\u7ee9\u8981\u5206\u300c\u4f18\u79c0\u3001\u826f\u597d\u3001\u53ca\u683c\u3001\u4e0d\u53ca\u683c\u300d\u56db\u6863\u3002\u8fd9\u65f6\u7528 <strong>elif<\/strong>\uff08\u662f &#8220;else if&#8221; \u7684\u7f29\u5199\uff0c\u7ffb\u8bd1\u8fc7\u6765\u662f\u300c\u5426\u5219\u5982\u679c\u300d\uff09\uff1a<code>if<\/code> \u5f00\u5934\uff0c\u4e2d\u95f4\u82e5\u5e72\u4e2a <code>elif<\/code>\uff0c\u6700\u540e\u53ef\u9009 <code>else<\/code> \u515c\u5e95\u3002\u4e3a\u4ec0\u4e48\u5fc5\u5b66\uff1f\u56e0\u4e3a\u771f\u5b9e\u4e1a\u52a1\u5168\u662f\u591a\u6863\u5224\u65ad\u2014\u2014\u6210\u7ee9\u5206\u6863\u3001\u4f1a\u5458\u5206\u7ea7\u3001\u5929\u6c14\u5206\u7c7b\uff0c\u6ca1 elif \u5c31\u5f97\u5199\u4e00\u5768\u5d4c\u5957 if\uff0c\u53c8\u4e71\u53c8\u5bb9\u6613\u9519\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a0b\u5e8f\u4f1a<strong>\u4ece\u4e0a\u5230\u4e0b<\/strong>\u9010\u4e2a\u68c0\u67e5\u6761\u4ef6\uff1a\u54ea\u4e2a\u6761\u4ef6<strong>\u5148<\/strong>\u6210\u7acb\uff0c\u5c31\u6267\u884c\u54ea\u6bb5\u4ee3\u7801\uff0c<strong>\u540e\u9762\u7684\u6761\u4ef6\u4e00\u5f8b\u4e0d\u518d\u770b<\/strong>\uff08\u8fd9\u53eb\u4f5c\u300c\u77ed\u8def\u300d\uff0c\u7b2c\u4e00\u4e2a\u547d\u4e2d\u7684\u5c31\u8d62\u4e86\uff09\u3002\u6240\u4ee5\u6761\u4ef6\u987a\u5e8f\u6781\u5176\u91cd\u8981\uff1a<strong>\u628a\u6700\u4e25\u683c\uff08\u6700\u96be\u6ee1\u8db3\uff09\u7684\u6761\u4ef6\u653e\u524d\u9762<\/strong>\uff0c\u5426\u5219\u4f1a\u88ab\u524d\u9762\u7684\u5bbd\u6761\u4ef6\u300c\u622a\u80e1\u300d\u3002\u6700\u540e\u4e00\u4e2a <code>else<\/code> \u515c\u5e95\u6240\u6709\u6ca1\u88ab\u547d\u4e2d\u7684\u60c5\u51b5\uff0c\u53ef\u5199\u53ef\u4e0d\u5199\uff0c\u4f46\u5199\u4e0a\u66f4\u7a33\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">elif \u94fe\u50cf<strong>\u6210\u7ee9\u53d1\u699c\u65f6\u7684\u6392\u540d\u5ba3\u8bfb<\/strong>\uff1a\u4ece\u7b2c\u4e00\u540d\uff08\u6700\u4e25\u683c\uff09\u5f00\u59cb\u5ff5\uff1a\u300c90 \u5206\u4ee5\u4e0a\u2014\u2014\u4f18\u79c0\uff1b80 \u5206\u4ee5\u4e0a\u2014\u2014\u826f\u597d\uff1b60 \u5206\u4ee5\u4e0a\u2014\u2014\u53ca\u683c\uff1b\u5176\u4f59\u2014\u2014\u4e0d\u53ca\u683c\u300d\u3002\u5ff5\u5230\u4f60\u540d\u5b57\u7684\u90a3\u4e00\u523b\uff08\u7b2c\u4e00\u4e2a\u547d\u4e2d\u7684\u6761\u4ef6\uff09\uff0c\u540e\u9762\u7684\u540d\u5355\u5c31\u4e0d\u518d\u5ff5\u4e86\u2014\u2014\u4f60\u4e0d\u4f1a\u540c\u65f6\u662f\u300c\u4f18\u79c0\u300d\u53c8\u662f\u300c\u826f\u597d\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u591a\u6863\u5224\u65ad\uff08\u6761\u4ef6\u4ece\u9ad8\u5230\u4f4e\u5199\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score = 85\nif score &gt;= 90:\n    print(\"\u4f18\u79c0\")\nelif score &gt;= 80:\n    print(\"\u826f\u597d\")\nelif score &gt;= 60:\n    print(\"\u53ca\u683c\")\nelse:\n    print(\"\u4e0d\u53ca\u683c\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u826f\u597d\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7a0b\u5e8f\u4ece\u4e0a\u5f80\u4e0b\u95ee\uff1a85 \u2265 90\uff1f\u5426 \u2192 85 \u2265 80\uff1f<strong>\u662f<\/strong> \u2192 \u8f93\u51fa\u300c\u826f\u597d\u300d\uff0c\u540e\u9762\u7684 elif\/else \u4e0d\u518d\u770b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u6761\u4ef6\u987a\u5e8f\u5f88\u91cd\u8981\uff08\u7ecf\u5178\u9677\u9631\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>score = 95\nif score &gt;= 60:\n    print(\"\u53ca\u683c\")      # 95 &gt;= 60 \u5148\u6210\u7acb\uff0c\u76f4\u63a5\u8f93\u51fa\u8fd9\u53e5\nelif score &gt;= 90:\n    print(\"\u4f18\u79c0\")      # \u8fd9\u884c\u6c38\u8fdc\u4e0d\u4f1a\u6267\u884c\uff01\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u53ca\u683c\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">95 \u2265 60 \u7b2c\u4e00\u4e2a\u5c31\u6210\u7acb\uff0c\u540e\u9762\u7684\u300c\u4f18\u79c0\u300d\u5206\u652f<strong>\u6c38\u8fdc\u8f6e\u4e0d\u5230<\/strong>\u2014\u2014\u8fd9\u5c31\u662f\u300c\u622a\u80e1\u300d\u3002<strong>\u5199\u591a\u5206\u652f\u65f6\uff0c\u6761\u4ef6\u987a\u5e8f\u5fc5\u987b\u7cbe\u5fc3\u8bbe\u8ba1\uff1a\u4ece\u6700\u4e25\u683c\u5230\u6700\u5bbd\u677e\u3002<\/strong>\uff08\u300c\u5206\u6570\u533a\u95f4\u300d\u8fd9\u7c7b<strong>\u6709\u91cd\u53e0<\/strong>\u7684\u6761\u4ef6\u987a\u5e8f\u624d\u81f3\u5173\u91cd\u8981\uff1b\u50cf\u300c\u6674\u5929\/\u4e0b\u96e8\/\u4e0b\u96ea\u300d\u8fd9\u79cd\u4e92\u65a5\u6761\u4ef6\uff0c\u987a\u5e8f\u5c31\u4e0d\u654f\u611f\u3002\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>elif score >= 80:<\/code> \u5199\u6210 <code>elif:<\/code>\uff08\u5fd8\u5199\u6761\u4ef6\uff09 \u2192 \u95ee\u9898\uff1aelif \u5fc5\u987b\u5e26\u6761\u4ef6\uff0c\u62a5 <code>SyntaxError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>elif \u6761\u4ef6:<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u6761\u4ef6\u987a\u5e8f\u98a0\u5012\uff08\u5148 \u226560 \u518d \u226590\uff09 \u2192 \u95ee\u9898\uff1a\u4f18\u79c0\u88ab\u300c\u53ca\u683c\u300d\u622a\u80e1\uff0c\u6c38\u8fdc\u51fa\u4e0d\u6765 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u4ece\u4e25\u683c\u5230\u5bbd\u677e\uff1a\u226590 \u2192 \u226580 \u2192 \u226560 \u2192 else\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1aelif \u4e0e if \u7f29\u8fdb\u4e0d\u5bf9\u9f50 \u2192 \u95ee\u9898\uff1a\u7ed3\u6784\u9519\u4e71\uff0c\u62a5\u8bed\u6cd5\u9519\u8bef \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6240\u6709 elif\u3001else \u4e0e if \u9876\u683c\u5bf9\u9f50\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u6f0f\u6389\u8fb9\u754c\uff08\u5982\u6ca1\u5199 <code>>= 60<\/code> \u7684 <code>>=<\/code>\uff0c\u5199\u6210 <code>> 60<\/code>\uff09 \u2192 \u95ee\u9898\uff1a\u6b63\u597d 60 \u5206\u7684\u4eba\u843d\u7a7a \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u60f3\u6e05\u695a\u8fb9\u754c\u5f52\u5c5e\uff0c<code>>= 60<\/code> \u5305\u542b 60 \u5206\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u591a\u5206\u652f\u7528 elif\uff0c\u4ece\u4e0a\u5230\u4e0b\u9010\u4e2a\u95ee\uff1b\u5148\u4e2d\u5148\u8d70\u540e\u9762\u770b\uff0c\u4e25\u683c\u6761\u4ef6\u6392\u524d\u9762\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5 \u903b\u8f91\u7ec4\u5408\u4e0e\u5d4c\u5957 \u2014\u2014 \u8ba9\u5224\u65ad\u66f4\u6709\u5c42\u6b21<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u903b\u8f91\u7ec4\u5408<\/strong>\u662f\u7528 <code>and<\/code> \/ <code>or<\/code> \/ <code>not<\/code> \u628a\u591a\u4e2a\u6761\u4ef6\u5408\u6210\u4e00\u4e2a\uff1b<strong>\u5d4c\u5957<\/strong>\u662f if \u91cc\u9762\u518d\u653e\u4e00\u4e2a if\uff0c\u5904\u7406\u300c\u5148\u8fc7\u7b2c\u4e00\u5173\u3001\u518d\u770b\u7b2c\u4e8c\u5173\u300d\u7684\u6d41\u7a0b\u3002\u4e3a\u4ec0\u4e48\u96f6\u57fa\u7840\u5fc5\u5b66\uff1f\u56e0\u4e3a\u73b0\u5b9e\u6761\u4ef6\u4ece\u6765\u4e0d\u662f\u5355\u4e00\u7ef4\u5ea6\u7684\u2014\u2014\u300c\u6210\u5e74<strong>\u4e14<\/strong>\u53ca\u683c\u300d\u300cVIP <strong>\u6216<\/strong>\u6ee1 100\u300d\u300c<strong>\u4e0d<\/strong>\u4e0b\u96e8\u624d\u51fa\u95e8\u300d\uff1b\u800c\u5d4c\u5957\u662f\u5206\u6b65\u5224\u65ad\u7684\u81ea\u7136\u8868\u8fbe\u3002\u4e24\u8005\u7ed3\u5408\uff0c\u7a0b\u5e8f\u624d\u80fd\u5e94\u5bf9\u771f\u5b9e\u4e16\u754c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e09\u4e2a\u5173\u952e\u539f\u7406\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>and<\/strong>\uff1a\u4e24\u8fb9\u90fd\u771f\u624d\u771f\uff0c\u53ea\u8981\u5de6\u8fb9\u662f False\uff0c\u53f3\u8fb9<strong>\u6839\u672c\u4e0d\u6267\u884c<\/strong>\uff08\u77ed\u8def\u6c42\u503c\uff09\u3002<\/li>\n\n\n\n<li><strong>or<\/strong>\uff1a\u4e00\u8fb9\u771f\u5c31\u771f\uff0c\u53ea\u8981\u5de6\u8fb9\u662f True\uff0c\u53f3\u8fb9<strong>\u6839\u672c\u4e0d\u6267\u884c<\/strong>\u3002<\/li>\n\n\n\n<li><strong>\u4f18\u5148\u7ea7<\/strong>\uff1a<code>not<\/code> > <code>and<\/code> > <code>or<\/code>\uff0c\u62ff\u4e0d\u51c6\u5c31\u52a0\u62ec\u53f7\u3002<\/li>\n\n\n\n<li><strong>\u5d4c\u5957<\/strong>\uff1a\u5185\u5c42 if \u7f29\u8fdb\u5728\u5916\u5c42 if \u7684\u5757\u91cc\uff0c\u5916\u5c42\u6761\u4ef6\u4e0d\u6210\u7acb\u65f6\uff0c\u5185\u5c42\u6574\u4e2a\u4e0d\u53c2\u4e0e\u3002\u5d4c\u5957\u8ba9\u4ee3\u7801\u53d8\u300c\u6df1\u300d\uff0c<strong>\u8d85\u8fc7\u4e24\u5c42\u5efa\u8bae\u6539\u7528 and \/ or \u5c55\u5e73<\/strong>\uff0c\u66f4\u5e73\u66f4\u597d\u8bfb\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u903b\u8f91\u7ec4\u5408\u50cf<strong>\u8d2d\u7269\u5e73\u53f0\u7684\u514d\u8fd0\u8d39\u89c4\u5219<\/strong>\uff1a\u300cVIP <strong>\u6216<\/strong> \u5b9e\u4ed8\u6ee1 100 \u5143\u514d\u8fd0\u8d39\u300d\u2014\u2014\u6ee1\u8db3\u4efb\u610f\u4e00\u4e2a\u5c31\u514d\uff08or\uff09\uff1b\u300c\u751f\u9c9c <strong>\u5e76\u4e14<\/strong> \u5f53\u5929\u9001\u8fbe\u624d\u4fdd\u9c9c\u300d\u2014\u2014\u7f3a\u4e00\u4e2a\u90fd\u4e0d\u884c\uff08and\uff09\uff1b\u300c<strong>\u4e0d<\/strong>\u4e0b\u96e8\u624d\u529e\u9732\u5929\u6d3b\u52a8\u300d\u2014\u2014\u5929\u6c14\u53d6\u53cd\uff08not\uff09\u3002\u5d4c\u5957\u50cf<strong>\u673a\u573a\u5b89\u68c0<\/strong>\uff1a\u5148\u67e5\u8bc1\u4ef6\uff08\u5916\u5c42 if\uff09\uff0c\u8fc7\u4e86\u624d\u67e5\u884c\u674e\uff08\u5185\u5c42 if\uff09\uff0c\u7b2c\u4e00\u5173\u6ca1\u8fc7\uff0c\u7b2c\u4e8c\u5173\u6839\u672c\u6ca1\u673a\u4f1a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>and \u2014\u2014 \u4e24\u8fb9\u90fd\u5f97\u6210\u7acb<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>age = 20\nscore = 88\nif age &gt;= 18 and score &gt;= 60:\n    print(\"\u6210\u5e74\u4e14\u53ca\u683c\uff0c\u53ef\u4ee5\u6bd5\u4e1a\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6210\u5e74\u4e14\u53ca\u683c\uff0c\u53ef\u4ee5\u6bd5\u4e1a\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u8981\u6709\u4e00\u8fb9\u4e0d\u6210\u7acb\uff0c\u6574\u4f53\u5c31\u662f False\u2014\u2014\u628a age \u6539\u6210 16 \u8bd5\u8bd5\uff0c\u4ec0\u4e48\u90fd\u4e0d\u4f1a\u8f93\u51fa\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>or \u2014\u2014 \u4e00\u8fb9\u6210\u7acb\u5c31\u884c<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>is_vip = True\namount = 30\nif is_vip or amount &gt;= 100:\n    print(\"\u514d\u8fd0\u8d39\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u514d\u8fd0\u8d39\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u628a is_vip \u6539\u6210 False\u3001amount \u4fdd\u6301 30\uff0c\u6761\u4ef6\u5c31\u53d8\u6210 False\uff0c\u4e0d\u4f1a\u8f93\u51fa\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3 <strong>not \u2014\u2014 \u53d6\u53cd<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>is_raining = False\nif not is_raining:\n    print(\"\u6ca1\u4e0b\u96e8\uff0c\u53ef\u4ee5\u51fa\u95e8\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6ca1\u4e0b\u96e8\uff0c\u53ef\u4ee5\u51fa\u95e8\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>not is_raining<\/code> \u628a False \u53d6\u53cd\u6210 True\u3002\u7ffb\u8bd1\u6210\u5927\u767d\u8bdd\u5c31\u662f\u300c\u5982\u679c\u4e0d\uff08\u5728\u4e0b\u96e8\uff09\u2192 \u51fa\u95e8\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4 <strong>\u5d4c\u5957 \u2014\u2014 \u5148\u8fc7\u7b2c\u4e00\u5173\uff0c\u518d\u770b\u7b2c\u4e8c\u5173<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>has_ticket = True\nseat = \"\u9760\u7a97\"\nif has_ticket:\n    print(\"\u68c0\u7968\u901a\u8fc7\")\n    if seat == \"\u9760\u7a97\":\n        print(\"\u53ef\u4ee5\u770b\u98ce\u666f\")\n    else:\n        print(\"\u666e\u901a\u5ea7\u4f4d\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u68c0\u7968\u901a\u8fc7\n\u53ef\u4ee5\u770b\u98ce\u666f\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5916\u5c42\u6210\u7acb\uff0c\u5148\u8f93\u51fa\u300c\u68c0\u7968\u901a\u8fc7\u300d\uff1b\u63a5\u7740\u8fdb\u5165\u5185\u5c42 if \u5224\u65ad\u5ea7\u4f4d\u3002\u628a has_ticket \u6539\u6210 False\uff0c\u5185\u5916\u5c42\u90fd\u4e0d\u4f1a\u6267\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">5 <strong>\u5d4c\u5957\u767b\u5f55 + \u7528 and \u5c55\u5e73<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>username = \"admin\"\npassword = \"123456\"\nif username == \"admin\":\n    if password == \"123456\":\n        print(\"\u767b\u5f55\u6210\u529f\")\n    else:\n        print(\"\u5bc6\u7801\u9519\u8bef\")\nelse:\n    print(\"\u7528\u6237\u540d\u4e0d\u5b58\u5728\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u767b\u5f55\u6210\u529f\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u4e2a\u6761\u4ef6\u662f\u300c\u4e14\u300d\u7684\u5173\u7cfb\uff0c\u53ef\u4ee5\u76f4\u63a5\u5c55\u5e73\u5199\u6210 <code>if username == \"admin\" and password == \"123456\":<\/code> \u4e00\u5c42\u641e\u5b9a\u3002<strong>\u80fd\u5e73\u5c31\u4e0d\u6df1<\/strong>\uff0c\u662f\u5224\u65ad\u4ee3\u7801\u7684\u5ba1\u7f8e\u6807\u51c6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>if a > 5 or b &lt; 10 and c == 1:<\/code>\uff08\u6df7\u7528\u4e0d\u62ec\u53f7\uff09 \u2192 \u95ee\u9898\uff1a<code>and<\/code> \u6bd4 <code>or<\/code> \u4f18\u5148\uff0c\u5b9e\u9645\u542b\u4e49\u548c\u4f60\u4ee5\u4e3a\u7684\u53ef\u80fd\u4e0d\u540c \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>if (a > 5) or ((b &lt; 10) and (c == 1)):<\/code> \u52a0\u62ec\u53f7\u660e\u786e\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u5d4c\u5957\u4e09\u5c42\u4ee5\u4e0a\u8fd8\u786c\u5199 \u2192 \u95ee\u9898\uff1a\u7f29\u8fdb\u8d8a\u6765\u8d8a\u6df1\uff0c\u4ee3\u7801\u7ed5\u6210\u8ff7\u5bab \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u7528 and \/ or \u5c55\u5e73\uff0c\u6216\u62c6\u6210\u591a\u4e2a if\uff08Day 9 \u5b66\u51fd\u6570\u540e\u53ef\u8fdb\u4e00\u6b65\u5c01\u88c5\uff09\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u5185\u5c42 if \u4e0e\u5916\u5c42 if \u7f29\u8fdb\u540c\u7ea7 \u2192 \u95ee\u9898\uff1a\u4e0d\u518d\u662f\u5d4c\u5957\uff0c\u53d8\u6210\u4e86\u300c\u4e24\u4e2a\u72ec\u7acb\u7684 if\u300d\uff0c\u903b\u8f91\u53d8\u5473 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5185\u5c42\u6bd4\u5916\u5c42\u591a\u7f29\u8fdb\u4e00\u5c42\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>if is_raining == False:<\/code> \u2192 \u95ee\u9898\uff1a\u80fd\u8fd0\u884c\u4f46\u7ed5 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>if not is_raining:<\/code> \u66f4\u76f4\u767d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1aand \u5168\u771f or \u4e00\u771f\uff0cnot \u53d6\u53cd\u8bb0\u5f97\u6e05\uff1b\u5d4c\u5957\u522b\u8d85\u4e24\u5c42\uff0c\u903b\u8f91\u7ec4\u5408\u66f4\u7701\u5fc3\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6 \u52a8\u624b\u5b9e\u8df5\uff1a\u6210\u7ee9\u7b49\u7ea7\u8bc4\u5b9a\u5668<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5199\u4e00\u4e2a\u7a0b\u5e8f\uff1a\u8f93\u5165\u4e00\u4e2a 0~100 \u7684\u5206\u6570\uff0c\u8f93\u51fa\u5bf9\u5e94\u7684\u7b49\u7ea7\u3002\u7b49\u7ea7\u89c4\u5219\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>90 \u53ca\u4ee5\u4e0a\uff1a\u4f18\u79c0<\/li>\n\n\n\n<li>80~89\uff1a\u826f\u597d<\/li>\n\n\n\n<li>70~79\uff1a\u4e2d\u7b49<\/li>\n\n\n\n<li>60~69\uff1a\u53ca\u683c<\/li>\n\n\n\n<li>60 \u4ee5\u4e0b\uff1a\u4e0d\u53ca\u683c<\/li>\n\n\n\n<li>\u8f93\u5165\u4e0d\u5728 0~100 \u65f6\u63d0\u793a\u300c\u5206\u6570\u4e0d\u5408\u6cd5\u300d<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6210\u7ee9\u7b49\u7ea7\u8bc4\u5b9a\u5668\nscore = int(input(\"\u8bf7\u8f93\u5165\u6210\u7ee9\uff080~100\uff09\uff1a\"))\n\nif score &lt; 0 or score &gt; 100:\n    print(\"\u5206\u6570\u4e0d\u5408\u6cd5\uff0c\u8bf7\u8f93\u5165 0~100 \u4e4b\u95f4\u7684\u6570\u5b57\")\nelif score &gt;= 90:\n    print(\"\u4f18\u79c0\")\nelif score &gt;= 80:\n    print(\"\u826f\u597d\")\nelif score &gt;= 70:\n    print(\"\u4e2d\u7b49\")\nelif score &gt;= 60:\n    print(\"\u53ca\u683c\")\nelse:\n    print(\"\u4e0d\u53ca\u683c\")\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bd5\u7740\u8f93\u5165 95\u300182\u300176\u300160\u300158\u3001-5 \u8fd0\u884c\u770b\u770b\u6548\u679c\u2014\u2014\u6ce8\u610f <code>score &lt; 0 or score &gt; 100<\/code> \u7528\u4e86 <strong>or \u7ec4\u5408\u6761\u4ef6<\/strong>\u5904\u7406\u975e\u6cd5\u8f93\u5165\uff0c\u800c\u5206\u6570\u533a\u95f4\u7528\u4e86<strong>\u4ece\u9ad8\u5230\u4f4e\u7684 elif \u987a\u5e8f<\/strong>\uff0c\u4e24\u5904\u90fd\u662f\u4eca\u5929\u5b66\u7684\u91cd\u70b9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4eca\u65e5\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5e03\u5c14\u503c\u53ea\u6709 True \/ False\uff1b\u6761\u4ef6\u8868\u8fbe\u5f0f\u4f1a\u7b97\u51fa\u4e00\u4e2a\u5e03\u5c14\u503c\n<code>==<\/code> \u5224\u65ad\u76f8\u7b49\uff0c<code>=<\/code> \u662f\u8d4b\u503c\uff0c\u4e24\u8005\u4e0d\u80fd\u6df7\u7528\n<code>if<\/code> \u6761\u4ef6\u6210\u7acb\u624d\u6267\u884c\u7f29\u8fdb\u4ee3\u7801\uff1b\u5192\u53f7\u548c\u7f29\u8fdb\u7f3a\u4e00\u4e0d\u53ef\n<code>else<\/code> \u5904\u7406\u300c\u5426\u5219\u300d\u7684\u60c5\u51b5\uff1belse \u4e0d\u5199\u6761\u4ef6\u3001\u4e0e if \u9876\u683c\u5bf9\u9f50\n<code>elif<\/code> \u591a\u5206\u652f\u65f6\uff0c\u628a\u6700\u4e25\u683c\u7684\u6761\u4ef6\u653e\u524d\u9762\uff0c\u9632\u6b62\u88ab\u622a\u80e1\n<code>and<\/code> \/ <code>or<\/code> \/ <code>not<\/code> \u53ef\u4ee5\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff1b<code>not<\/code> &gt; <code>and<\/code> &gt; <code>or<\/code>\uff0c\u62ff\u4e0d\u51c6\u52a0\u62ec\u53f7\n\u5d4c\u5957\u5224\u65ad\u9002\u5408\u300c\u5148\u8fc7\u7b2c\u4e00\u5173\u518d\u770b\u7b2c\u4e8c\u5173\u300d\uff1b\u8d85\u8fc7\u4e24\u5c42\u7528 and \/ or \u5c55\u5e73\n\u5b8c\u6210\u300c\u6210\u7ee9\u7b49\u7ea7\u8bc4\u5b9a\u5668\u300d\u5e76\u9a8c\u8bc1\u8fb9\u754c\u8f93\u5165\uff080\u300160\u300190\u3001100\u3001-5\uff09<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u62a5\u9519<\/th><th>\u539f\u56e0<\/th><th>\u4fee\u590d<\/th><\/tr><\/thead><tbody><tr><td><code>IndentationError: expected an indented block<\/code><\/td><td>if \u4e0b\u9762\u5fd8\u4e86\u7f29\u8fdb<\/td><td>if \u4e0b\u4e00\u884c\u6309 Tab \u6216 4 \u4e2a\u7a7a\u683c\u518d\u5199\u4ee3\u7801<\/td><\/tr><tr><td><code>SyntaxError: invalid syntax<\/code><\/td><td>if \u6761\u4ef6\u540e\u9762\u5fd8\u4e86\u5199\u5192\u53f7 <code>:<\/code><\/td><td>\u68c0\u67e5\u662f\u4e0d\u662f <code>if x &gt; 5:<\/code> \u5c11\u4e86\u5192\u53f7<\/td><\/tr><tr><td><code>SyntaxError: cannot assign to literal<\/code><\/td><td>\u628a <code>==<\/code> \u5199\u6210\u4e86 <code>=<\/code><\/td><td>\u5224\u65ad\u76f8\u7b49\u7528 <code>==<\/code>\uff0c<code>=<\/code> \u53ea\u7528\u4e8e\u8d4b\u503c<\/td><\/tr><tr><td><code>IndentationError: unexpected indent<\/code><\/td><td>\u67d0\u884c\u591a\u7f29\u8fdb\u4e86\uff0cPython \u5224\u65ad\u4e0d\u51fa\u6765\u5386<\/td><td>\u68c0\u67e5\u6bcf\u884c\u7f29\u8fdb\u662f\u5426\u4e00\u81f4\uff08\u8981\u4e48\u5168 Tab\uff0c\u8981\u4e48\u5168\u7a7a\u683c\uff09<\/td><\/tr><tr><td><code>TypeError: '&gt;' not supported between instances of 'str' and 'int'<\/code><\/td><td>\u62ff\u5b57\u7b26\u4e32\u548c\u6570\u5b57\u6bd4\u8f83<\/td><td>\u5148\u7528 <code>int()<\/code> \/ <code>float()<\/code> \u628a\u8f93\u5165\u8f6c\u6210\u6570\u5b57<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1 \u5e03\u5c14\u503c \u2014\u2014 \u7a0b\u5e8f\u5224\u65ad\u7684\u300c\u5f00\u5173\u300d \u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f \u5e03\u5c14\u503c\uff08bool\uff09\u53ea\u6709\u4e24\u4e2a\uff1aTrue\uff08\u771f\uff09\u548c Fal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[16,9],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-python","category-code-dev"],"_links":{"self":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":2,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":133,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions\/133"}],"wp:attachment":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}