{"id":587,"date":"2025-10-23T15:27:41","date_gmt":"2025-10-23T07:27:41","guid":{"rendered":"http:\/\/www.pyteam.cn\/?p=587"},"modified":"2025-10-23T15:27:41","modified_gmt":"2025-10-23T07:27:41","slug":"python3-%e8%bf%90%e7%ae%97%e7%ac%a6","status":"publish","type":"post","link":"http:\/\/www.pyteam.cn\/index.php\/2025\/10\/23\/python3-%e8%bf%90%e7%ae%97%e7%ac%a6\/","title":{"rendered":"Python3\u00a0\u8fd0\u7b97\u7b26"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ec0\u4e48\u662f\u8fd0\u7b97\u7b26\uff1f<\/h2>\n\n\n\n<p>\u672c\u7ae0\u8282\u4e3b\u8981\u8bf4\u660e Python \u7684\u8fd0\u7b97\u7b26\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">4 + 5 = 9<\/pre>\n\n\n\n<p>\u4f8b\u5b50\u4e2d\uff0c<strong>4<\/strong>&nbsp;\u548c&nbsp;<strong>5<\/strong>&nbsp;\u88ab\u79f0\u4e3a<strong>\u64cd\u4f5c\u6570<\/strong>\uff0c<strong>+<\/strong>&nbsp;\u79f0\u4e3a<strong>\u8fd0\u7b97\u7b26<\/strong>\u3002<\/p>\n\n\n\n<p>Python \u8bed\u8a00\u652f\u6301\u4ee5\u4e0b\u7c7b\u578b\u7684\u8fd0\u7b97\u7b26:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf1\">\u7b97\u672f\u8fd0\u7b97\u7b26<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf2\">\u6bd4\u8f83\uff08\u5173\u7cfb\uff09\u8fd0\u7b97\u7b26<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf3\">\u8d4b\u503c\u8fd0\u7b97\u7b26<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf4\">\u903b\u8f91\u8fd0\u7b97\u7b26<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf5\">\u4f4d\u8fd0\u7b97\u7b26<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf6\">\u6210\u5458\u8fd0\u7b97\u7b26<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf7\">\u8eab\u4efd\u8fd0\u7b97\u7b26<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.runoob.com\/python3\/python3-basic-operators.html#ysf8\">\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7<\/a><\/li>\n<\/ul>\n\n\n\n<p>\u63a5\u4e0b\u6765\u8ba9\u6211\u4eec\u4e00\u4e2a\u4e2a\u6765\u5b66\u4e60Python\u7684\u8fd0\u7b97\u7b26\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf1\">Python\u7b97\u672f\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u5047\u8bbe\u53d8\u91cf&nbsp;<strong>a=10<\/strong>\uff0c\u53d8\u91cf&nbsp;<strong>b=21<\/strong>\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>+<\/td><td>\u52a0 &#8211; \u4e24\u4e2a\u5bf9\u8c61\u76f8\u52a0<\/td><td>a + b \u8f93\u51fa\u7ed3\u679c 31<\/td><\/tr><tr><td>&#8211;<\/td><td>\u51cf &#8211; \u5f97\u5230\u8d1f\u6570\u6216\u662f\u4e00\u4e2a\u6570\u51cf\u53bb\u53e6\u4e00\u4e2a\u6570<\/td><td>a &#8211; b \u8f93\u51fa\u7ed3\u679c -11<\/td><\/tr><tr><td>*<\/td><td>\u4e58 &#8211; \u4e24\u4e2a\u6570\u76f8\u4e58\u6216\u662f\u8fd4\u56de\u4e00\u4e2a\u88ab\u91cd\u590d\u82e5\u5e72\u6b21\u7684\u5b57\u7b26\u4e32<\/td><td>a * b \u8f93\u51fa\u7ed3\u679c 210<\/td><\/tr><tr><td>\/<\/td><td>\u9664 &#8211; x \u9664\u4ee5 y<\/td><td>b \/ a \u8f93\u51fa\u7ed3\u679c 2.1<\/td><\/tr><tr><td>%<\/td><td>\u53d6\u6a21 &#8211; \u8fd4\u56de\u9664\u6cd5\u7684\u4f59\u6570<\/td><td>b % a \u8f93\u51fa\u7ed3\u679c 1<\/td><\/tr><tr><td>**<\/td><td>\u5e42 &#8211; \u8fd4\u56dex\u7684y\u6b21\u5e42<\/td><td>a**b \u4e3a10\u768421\u6b21\u65b9<\/td><\/tr><tr><td>\/\/<\/td><td>\u53d6\u6574\u9664 &#8211; \u5f80\u5c0f\u7684\u65b9\u5411\u53d6\u6574\u6570<\/td><td>&gt;&gt;&gt; 9\/\/2 4 &gt;&gt;&gt; -9\/\/2 -5<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u7b97\u672f\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 21 b = 10 c = 0 c = a + b print (&#8220;1 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a &#8211; b print (&#8220;2 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a * b print (&#8220;3 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a \/ b print (&#8220;4 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a % b print (&#8220;5 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) # \u4fee\u6539\u53d8\u91cf a \u3001b \u3001c a = 2 b = 3 c = a**b print (&#8220;6 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) a = 10 b = 5 c = a\/\/b print (&#8220;7 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 - c \u7684\u503c\u4e3a\uff1a 31\n2 - c \u7684\u503c\u4e3a\uff1a 11\n3 - c \u7684\u503c\u4e3a\uff1a 210\n4 - c \u7684\u503c\u4e3a\uff1a 2.1\n5 - c \u7684\u503c\u4e3a\uff1a 1\n6 - c \u7684\u503c\u4e3a\uff1a 8\n7 - c \u7684\u503c\u4e3a\uff1a 2<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf2\">Python \u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u5047\u8bbe\u53d8\u91cf a \u4e3a 10\uff0c\u53d8\u91cf b \u4e3a20\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>==<\/td><td>\u7b49\u4e8e &#8211; \u6bd4\u8f83\u5bf9\u8c61\u662f\u5426\u76f8\u7b49<\/td><td>(a == b) \u8fd4\u56de False\u3002<\/td><\/tr><tr><td>!=<\/td><td>\u4e0d\u7b49\u4e8e &#8211; \u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u662f\u5426\u4e0d\u76f8\u7b49<\/td><td>(a != b) \u8fd4\u56de True\u3002<\/td><\/tr><tr><td>&gt;<\/td><td>\u5927\u4e8e &#8211; \u8fd4\u56dex\u662f\u5426\u5927\u4e8ey<\/td><td>(a &gt; b) \u8fd4\u56de False\u3002<\/td><\/tr><tr><td>&lt;<\/td><td>\u5c0f\u4e8e &#8211; \u8fd4\u56dex\u662f\u5426\u5c0f\u4e8ey\u3002\u6240\u6709\u6bd4\u8f83\u8fd0\u7b97\u7b26\u8fd4\u56de1\u8868\u793a\u771f\uff0c\u8fd4\u56de0\u8868\u793a\u5047\u3002\u8fd9\u5206\u522b\u4e0e\u7279\u6b8a\u7684\u53d8\u91cfTrue\u548cFalse\u7b49\u4ef7\u3002\u6ce8\u610f\uff0c\u8fd9\u4e9b\u53d8\u91cf\u540d\u7684\u5927\u5199\u3002<\/td><td>(a &lt; b) \u8fd4\u56de True\u3002<\/td><\/tr><tr><td>&gt;=<\/td><td>\u5927\u4e8e\u7b49\u4e8e &#8211; \u8fd4\u56dex\u662f\u5426\u5927\u4e8e\u7b49\u4e8ey\u3002<\/td><td>(a &gt;= b) \u8fd4\u56de False\u3002<\/td><\/tr><tr><td>&lt;=<\/td><td>\u5c0f\u4e8e\u7b49\u4e8e &#8211; \u8fd4\u56dex\u662f\u5426\u5c0f\u4e8e\u7b49\u4e8ey\u3002<\/td><td>(a &lt;= b) \u8fd4\u56de True\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u6bd4\u8f83\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 21 b = 10 c = 0 if ( a == b ): print (&#8220;1 &#8211; a \u7b49\u4e8e b&#8221;) else: print (&#8220;1 &#8211; a \u4e0d\u7b49\u4e8e b&#8221;) if ( a != b ): print (&#8220;2 &#8211; a \u4e0d\u7b49\u4e8e b&#8221;) else: print (&#8220;2 &#8211; a \u7b49\u4e8e b&#8221;) if ( a &lt; b ): print (&#8220;3 &#8211; a \u5c0f\u4e8e b&#8221;) else: print (&#8220;3 &#8211; a \u5927\u4e8e\u7b49\u4e8e b&#8221;) if ( a &gt; b ): print (&#8220;4 &#8211; a \u5927\u4e8e b&#8221;) else: print (&#8220;4 &#8211; a \u5c0f\u4e8e\u7b49\u4e8e b&#8221;) # \u4fee\u6539\u53d8\u91cf a \u548c b \u7684\u503c a = 5 b = 20 if ( a &lt;= b ): print (&#8220;5 &#8211; a \u5c0f\u4e8e\u7b49\u4e8e b&#8221;) else: print (&#8220;5 &#8211; a \u5927\u4e8e b&#8221;) if ( b &gt;= a ): print (&#8220;6 &#8211; b \u5927\u4e8e\u7b49\u4e8e a&#8221;) else: print (&#8220;6 &#8211; b \u5c0f\u4e8e a&#8221;)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 - a \u4e0d\u7b49\u4e8e b\n2 - a \u4e0d\u7b49\u4e8e b\n3 - a \u5927\u4e8e\u7b49\u4e8e b\n4 - a \u5927\u4e8e b\n5 - a \u5c0f\u4e8e\u7b49\u4e8e b\n6 - b \u5927\u4e8e\u7b49\u4e8e a<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf3\">Python\u8d4b\u503c\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u5047\u8bbe\u53d8\u91cfa\u4e3a10\uff0c\u53d8\u91cfb\u4e3a20\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>=<\/td><td>\u7b80\u5355\u7684\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c = a + b \u5c06 a + b \u7684\u8fd0\u7b97\u7ed3\u679c\u8d4b\u503c\u4e3a c<\/td><\/tr><tr><td>+=<\/td><td>\u52a0\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c += a \u7b49\u6548\u4e8e c = c + a<\/td><\/tr><tr><td>-=<\/td><td>\u51cf\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c -= a \u7b49\u6548\u4e8e c = c &#8211; a<\/td><\/tr><tr><td>*=<\/td><td>\u4e58\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c *= a \u7b49\u6548\u4e8e c = c * a<\/td><\/tr><tr><td>\/=<\/td><td>\u9664\u6cd5\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c \/= a \u7b49\u6548\u4e8e c = c \/ a<\/td><\/tr><tr><td>%=<\/td><td>\u53d6\u6a21\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c %= a \u7b49\u6548\u4e8e c = c % a<\/td><\/tr><tr><td>**=<\/td><td>\u5e42\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c **= a \u7b49\u6548\u4e8e c = c ** a<\/td><\/tr><tr><td>\/\/=<\/td><td>\u53d6\u6574\u9664\u8d4b\u503c\u8fd0\u7b97\u7b26<\/td><td>c \/\/= a \u7b49\u6548\u4e8e c = c \/\/ a<\/td><\/tr><tr><td>:=<\/td><td>\u6d77\u8c61\u8fd0\u7b97\u7b26\uff0c\u8fd9\u4e2a\u8fd0\u7b97\u7b26\u7684\u4e3b\u8981\u76ee\u7684\u662f\u5728\u8868\u8fbe\u5f0f\u4e2d\u540c\u65f6\u8fdb\u884c\u8d4b\u503c\u548c\u8fd4\u56de\u8d4b\u503c\u7684\u503c\u3002<strong>Python3.8 \u7248\u672c\u65b0\u589e\u8fd0\u7b97\u7b26<\/strong>\u3002<\/td><td>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u8d4b\u503c\u8868\u8fbe\u5f0f\u53ef\u4ee5\u907f\u514d\u8c03\u7528 len() \u4e24\u6b21:if (n := len(a)) &gt; 10: print(f&#8221;List is too long ({n} elements, expected &lt;= 10)&#8221;)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u8d4b\u503c\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 21 b = 10 c = 0 c = a + b print (&#8220;1 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c += a print (&#8220;2 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c *= a print (&#8220;3 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c \/= a print (&#8220;4 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = 2 c %= a print (&#8220;5 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c **= a print (&#8220;6 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c \/\/= a print (&#8220;7 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 - c \u7684\u503c\u4e3a\uff1a 31\n2 - c \u7684\u503c\u4e3a\uff1a 52\n3 - c \u7684\u503c\u4e3a\uff1a 1092\n4 - c \u7684\u503c\u4e3a\uff1a 52.0\n5 - c \u7684\u503c\u4e3a\uff1a 2\n6 - c \u7684\u503c\u4e3a\uff1a 2097152\n7 - c \u7684\u503c\u4e3a\uff1a 99864<\/pre>\n\n\n\n<p>\u5728 Python 3.8 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\uff0c\u5f15\u5165\u4e86\u4e00\u79cd\u65b0\u7684\u8bed\u6cd5\u7279\u6027\uff0c\u79f0\u4e3a&#8221;\u6d77\u8c61\u8fd0\u7b97\u7b26&#8221;\uff08Walrus Operator\uff09\uff0c\u5b83\u4f7f\u7528&nbsp;<strong>:=<\/strong>&nbsp;\u7b26\u53f7\u3002\u8fd9\u4e2a\u8fd0\u7b97\u7b26\u7684\u4e3b\u8981\u76ee\u7684\u662f\u5728\u8868\u8fbe\u5f0f\u4e2d\u540c\u65f6\u8fdb\u884c\u8d4b\u503c\u548c\u8fd4\u56de\u8d4b\u503c\u7684\u503c\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528\u6d77\u8c61\u8fd0\u7b97\u7b26\u53ef\u4ee5\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\u7b80\u5316\u4ee3\u7801\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u5728\u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7528\u8d4b\u503c\u7ed3\u679c\u7684\u60c5\u51b5\u4e0b\u3002\u8fd9\u5bf9\u4e8e\u7b80\u5316\u5faa\u73af\u6761\u4ef6\u6216\u8868\u8fbe\u5f0f\u4e2d\u7684\u91cd\u590d\u8ba1\u7b97\u5f88\u6709\u7528\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u4f8b\uff0c\u6f14\u793a\u4e86\u6d77\u8c61\u8fd0\u7b97\u7b26\u7684\u4f7f\u7528\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b<\/h2>\n\n\n\n<p># \u4f20\u7edf\u5199\u6cd5<br>n&nbsp;=&nbsp;10<br><strong>if<\/strong>&nbsp;n&nbsp;&gt;&nbsp;5:<br>&nbsp;<strong>print<\/strong>(n)<\/p>\n\n\n\n<p># \u4f7f\u7528\u6d77\u8c61\u8fd0\u7b97\u7b26<br><strong>if<\/strong>&nbsp;(n :=&nbsp;10)&nbsp;&gt;&nbsp;5:<br>&nbsp;<strong>print<\/strong>(n)<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>if (n := 10) > 5:<\/code>\uff1a\u8fd9\u662f\u4f7f\u7528\u6d77\u8c61\u8fd0\u7b97\u7b26\uff08<code>:=<\/code>\uff09\u7684\u5199\u6cd5\u3002\u6d77\u8c61\u8fd0\u7b97\u7b26\u5728\u8868\u8fbe\u5f0f\u4e2d\u8fdb\u884c\u8d4b\u503c\u64cd\u4f5c\u3002\n<ul class=\"wp-block-list\">\n<li><code>(n := 10)<\/code>\uff1a\u5c06\u53d8\u91cf\u00a0<code>n<\/code>\u00a0\u8d4b\u503c\u4e3a 10\uff0c\u540c\u65f6\u8fd4\u56de\u8fd9\u4e2a\u8d4b\u503c\u7ed3\u679c\u3002<\/li>\n\n\n\n<li><code>> 5<\/code>\uff1a\u68c0\u67e5\u8d4b\u503c\u540e\u7684\u00a0<code>n<\/code>\u00a0\u662f\u5426\u5927\u4e8e 5\u3002\u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u5219\u6267\u884c\u63a5\u4e0b\u6765\u7684\u4ee3\u7801\u5757\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>print(n)<\/code>\uff1a\u5982\u679c\u6761\u4ef6\u4e3a\u771f\uff0c\u6253\u5370\u53d8\u91cf\u00a0<code>n<\/code>\u00a0\u7684\u503c\uff08\u5373 10\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u6d77\u8c61\u8fd0\u7b97\u7b26\u7684\u4f18\u70b9\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6d77\u8c61\u8fd0\u7b97\u7b26\uff08<code>:=<\/code>\uff09\u5141\u8bb8\u5728\u8868\u8fbe\u5f0f\u5185\u90e8\u8fdb\u884c\u8d4b\u503c\uff0c\u8fd9\u53ef\u4ee5\u51cf\u5c11\u4ee3\u7801\u7684\u91cd\u590d\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u7b80\u6d01\u6027\u3002<\/li>\n\n\n\n<li>\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c\u4f20\u7edf\u5199\u6cd5\u9700\u8981\u5355\u72ec\u4e00\u884c\u6765\u8d4b\u503c\u00a0<code>n<\/code>\uff0c\u7136\u540e\u5728\u00a0<code>if<\/code>\u00a0\u8bed\u53e5\u4e2d\u8fdb\u884c\u6761\u4ef6\u68c0\u67e5\u3002\u800c\u4f7f\u7528\u6d77\u8c61\u8fd0\u7b97\u7b26\u7684\u5199\u6cd5\u53ef\u4ee5\u5728\u00a0<code>if<\/code>\u00a0\u8bed\u53e5\u4e2d\u76f4\u63a5\u8fdb\u884c\u8d4b\u503c\u548c\u6761\u4ef6\u68c0\u67e5\u3002<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf5\">Python\u4f4d\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>\u6309\u4f4d\u8fd0\u7b97\u7b26\u662f\u628a\u6570\u5b57\u770b\u4f5c\u4e8c\u8fdb\u5236\u6765\u8fdb\u884c\u8ba1\u7b97\u7684\u3002Python\u4e2d\u7684\u6309\u4f4d\u8fd0\u7b97\u6cd5\u5219\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>\u4e0b\u8868\u4e2d\u53d8\u91cf a \u4e3a 60\uff0cb \u4e3a 13\u4e8c\u8fdb\u5236\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a = 0011 1100\n\nb = 0000 1101\n\n-----------------\n\na&amp;b = 0000 1100\n\na|b = 0011 1101\n\na^b = 0011 0001\n\n~a  = 1100 0011<\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>&amp;<\/td><td>\u6309\u4f4d\u4e0e\u8fd0\u7b97\u7b26\uff1a\u53c2\u4e0e\u8fd0\u7b97\u7684\u4e24\u4e2a\u503c,\u5982\u679c\u4e24\u4e2a\u76f8\u5e94\u4f4d\u90fd\u4e3a1,\u5219\u8be5\u4f4d\u7684\u7ed3\u679c\u4e3a1,\u5426\u5219\u4e3a0<\/td><td>(a &amp; b) \u8f93\u51fa\u7ed3\u679c 12 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0000 1100<\/td><\/tr><tr><td>|<\/td><td>\u6309\u4f4d\u6216\u8fd0\u7b97\u7b26\uff1a\u53ea\u8981\u5bf9\u5e94\u7684\u4e8c\u4e2a\u4e8c\u8fdb\u4f4d\u6709\u4e00\u4e2a\u4e3a1\u65f6\uff0c\u7ed3\u679c\u4f4d\u5c31\u4e3a1\u3002<\/td><td>(a | b) \u8f93\u51fa\u7ed3\u679c 61 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0011 1101<\/td><\/tr><tr><td>^<\/td><td>\u6309\u4f4d\u5f02\u6216\u8fd0\u7b97\u7b26\uff1a\u5f53\u4e24\u5bf9\u5e94\u7684\u4e8c\u8fdb\u4f4d\u76f8\u5f02\u65f6\uff0c\u7ed3\u679c\u4e3a1<\/td><td>(a ^ b) \u8f93\u51fa\u7ed3\u679c 49 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0011 0001<\/td><\/tr><tr><td>~<\/td><td>\u6309\u4f4d\u53d6\u53cd\u8fd0\u7b97\u7b26\uff1a\u5bf9\u6570\u636e\u7684\u6bcf\u4e2a\u4e8c\u8fdb\u5236\u4f4d\u53d6\u53cd,\u5373\u628a1\u53d8\u4e3a0,\u628a0\u53d8\u4e3a1\u3002<strong>~x<\/strong>&nbsp;\u7c7b\u4f3c\u4e8e&nbsp;<strong>-x-1<\/strong><\/td><td>(~a ) \u8f93\u51fa\u7ed3\u679c -61 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 1100 0011\uff0c \u5728\u4e00\u4e2a\u6709\u7b26\u53f7\u4e8c\u8fdb\u5236\u6570\u7684\u8865\u7801\u5f62\u5f0f\u3002<\/td><\/tr><tr><td>&lt;&lt;<\/td><td>\u5de6\u79fb\u52a8\u8fd0\u7b97\u7b26\uff1a\u8fd0\u7b97\u6570\u7684\u5404\u4e8c\u8fdb\u4f4d\u5168\u90e8\u5de6\u79fb\u82e5\u5e72\u4f4d\uff0c\u7531&#8221;&lt;&lt;&#8220;\u53f3\u8fb9\u7684\u6570\u6307\u5b9a\u79fb\u52a8\u7684\u4f4d\u6570\uff0c\u9ad8\u4f4d\u4e22\u5f03\uff0c\u4f4e\u4f4d\u88650\u3002<\/td><td>a &lt;&lt; 2 \u8f93\u51fa\u7ed3\u679c 240 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 1111 0000<\/td><\/tr><tr><td>&gt;&gt;<\/td><td>\u53f3\u79fb\u52a8\u8fd0\u7b97\u7b26\uff1a\u628a&#8221;&gt;&gt;&#8221;\u5de6\u8fb9\u7684\u8fd0\u7b97\u6570\u7684\u5404\u4e8c\u8fdb\u4f4d\u5168\u90e8\u53f3\u79fb\u82e5\u5e72\u4f4d\uff0c&#8221;&gt;&gt;&#8221;\u53f3\u8fb9\u7684\u6570\u6307\u5b9a\u79fb\u52a8\u7684\u4f4d\u6570<\/td><td>a &gt;&gt; 2 \u8f93\u51fa\u7ed3\u679c 15 \uff0c\u4e8c\u8fdb\u5236\u89e3\u91ca\uff1a 0000 1111<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u4f4d\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 60 # 60 = 0011 1100 b = 13 # 13 = 0000 1101 c = 0 c = a &amp; b # 12 = 0000 1100 print (&#8220;1 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a | b # 61 = 0011 1101 print (&#8220;2 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a ^ b # 49 = 0011 0001 print (&#8220;3 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = ~a # -61 = 1100 0011 print (&#8220;4 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a &lt;&lt; 2 # 240 = 1111 0000 print (&#8220;5 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c) c = a &gt;&gt; 2 # 15 = 0000 1111 print (&#8220;6 &#8211; c \u7684\u503c\u4e3a\uff1a&#8221;, c)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 - c \u7684\u503c\u4e3a\uff1a 12\n2 - c \u7684\u503c\u4e3a\uff1a 61\n3 - c \u7684\u503c\u4e3a\uff1a 49\n4 - c \u7684\u503c\u4e3a\uff1a -61\n5 - c \u7684\u503c\u4e3a\uff1a 240\n6 - c \u7684\u503c\u4e3a\uff1a 15<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf4\">Python\u903b\u8f91\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>Python\u8bed\u8a00\u652f\u6301\u903b\u8f91\u8fd0\u7b97\u7b26\uff0c\u4ee5\u4e0b\u5047\u8bbe\u53d8\u91cf a \u4e3a 10, b\u4e3a 20:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u903b\u8f91\u8868\u8fbe\u5f0f<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>and<\/td><td>x and y<\/td><td>\u5e03\u5c14&#8221;\u4e0e&#8221; &#8211; \u5982\u679c x \u4e3a False\uff0cx and y \u8fd4\u56de x \u7684\u503c\uff0c\u5426\u5219\u8fd4\u56de y \u7684\u8ba1\u7b97\u503c\u3002<\/td><td>(a and b) \u8fd4\u56de 20\u3002<\/td><\/tr><tr><td>or<\/td><td>x or y<\/td><td>\u5e03\u5c14&#8221;\u6216&#8221; &#8211; \u5982\u679c x \u662f True\uff0c\u5b83\u8fd4\u56de x \u7684\u503c\uff0c\u5426\u5219\u5b83\u8fd4\u56de y \u7684\u8ba1\u7b97\u503c\u3002<\/td><td>(a or b) \u8fd4\u56de 10\u3002<\/td><\/tr><tr><td>not<\/td><td>not x<\/td><td>\u5e03\u5c14&#8221;\u975e&#8221; &#8211; \u5982\u679c x \u4e3a True\uff0c\u8fd4\u56de False \u3002\u5982\u679c x \u4e3a False\uff0c\u5b83\u8fd4\u56de True\u3002<\/td><td>not(a and b) \u8fd4\u56de False<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 10 b = 20 if ( a and b ): print (&#8220;1 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e3a true&#8221;) else: print (&#8220;1 &#8211; \u53d8\u91cf a \u548c b \u6709\u4e00\u4e2a\u4e0d\u4e3a true&#8221;) if ( a or b ): print (&#8220;2 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e3a true\uff0c\u6216\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u4e3a true&#8221;) else: print (&#8220;2 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e0d\u4e3a true&#8221;) # \u4fee\u6539\u53d8\u91cf a \u7684\u503c a = 0 if ( a and b ): print (&#8220;3 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e3a true&#8221;) else: print (&#8220;3 &#8211; \u53d8\u91cf a \u548c b \u6709\u4e00\u4e2a\u4e0d\u4e3a true&#8221;) if ( a or b ): print (&#8220;4 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e3a true\uff0c\u6216\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u4e3a true&#8221;) else: print (&#8220;4 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e0d\u4e3a true&#8221;) if not( a and b ): print (&#8220;5 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e3a false\uff0c\u6216\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u4e3a false&#8221;) else: print (&#8220;5 &#8211; \u53d8\u91cf a \u548c b \u90fd\u4e3a true&#8221;)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 - \u53d8\u91cf a \u548c b \u90fd\u4e3a true\n2 - \u53d8\u91cf a \u548c b \u90fd\u4e3a true\uff0c\u6216\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u4e3a true\n3 - \u53d8\u91cf a \u548c b \u6709\u4e00\u4e2a\u4e0d\u4e3a true\n4 - \u53d8\u91cf a \u548c b \u90fd\u4e3a true\uff0c\u6216\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u4e3a true\n5 - \u53d8\u91cf a \u548c b \u90fd\u4e3a false\uff0c\u6216\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u4e3a false<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf6\">Python\u6210\u5458\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>\u9664\u4e86\u4ee5\u4e0a\u7684\u4e00\u4e9b\u8fd0\u7b97\u7b26\u4e4b\u5916\uff0cPython\u8fd8\u652f\u6301\u6210\u5458\u8fd0\u7b97\u7b26\uff0c\u6d4b\u8bd5\u5b9e\u4f8b\u4e2d\u5305\u542b\u4e86\u4e00\u7cfb\u5217\u7684\u6210\u5458\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\uff0c\u5217\u8868\u6216\u5143\u7ec4\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>in<\/td><td>\u5982\u679c\u5728\u6307\u5b9a\u7684\u5e8f\u5217\u4e2d\u627e\u5230\u503c\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002<\/td><td>x \u5728 y \u5e8f\u5217\u4e2d , \u5982\u679c x \u5728 y \u5e8f\u5217\u4e2d\u8fd4\u56de True\u3002<\/td><\/tr><tr><td>not in<\/td><td>\u5982\u679c\u5728\u6307\u5b9a\u7684\u5e8f\u5217\u4e2d\u6ca1\u6709\u627e\u5230\u503c\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002<\/td><td>x \u4e0d\u5728 y \u5e8f\u5217\u4e2d , \u5982\u679c x \u4e0d\u5728 y \u5e8f\u5217\u4e2d\u8fd4\u56de True\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u6210\u5458\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 10 b = 20 list = [1, 2, 3, 4, 5 ] if ( a in list ): print (&#8220;1 &#8211; \u53d8\u91cf a \u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d&#8221;) else: print (&#8220;1 &#8211; \u53d8\u91cf a \u4e0d\u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d&#8221;) if ( b not in list ): print (&#8220;2 &#8211; \u53d8\u91cf b \u4e0d\u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d&#8221;) else: print (&#8220;2 &#8211; \u53d8\u91cf b \u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d&#8221;) # \u4fee\u6539\u53d8\u91cf a \u7684\u503c a = 2 if ( a in list ): print (&#8220;3 &#8211; \u53d8\u91cf a \u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d&#8221;) else: print (&#8220;3 &#8211; \u53d8\u91cf a \u4e0d\u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d&#8221;)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 - \u53d8\u91cf a \u4e0d\u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d\n2 - \u53d8\u91cf b \u4e0d\u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d\n3 - \u53d8\u91cf a \u5728\u7ed9\u5b9a\u7684\u5217\u8868\u4e2d list \u4e2d<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf7\">Python\u8eab\u4efd\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>\u8eab\u4efd\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u5b58\u50a8\u5355\u5143<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>is<\/td><td>is \u662f\u5224\u65ad\u4e24\u4e2a\u6807\u8bc6\u7b26\u662f\u4e0d\u662f\u5f15\u7528\u81ea\u4e00\u4e2a\u5bf9\u8c61<\/td><td><strong>x is y<\/strong>, \u7c7b\u4f3c&nbsp;<strong>id(x) == id(y)<\/strong>&nbsp;, \u5982\u679c\u5f15\u7528\u7684\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\u5219\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False<\/td><\/tr><tr><td>is not<\/td><td>is not \u662f\u5224\u65ad\u4e24\u4e2a\u6807\u8bc6\u7b26\u662f\u4e0d\u662f\u5f15\u7528\u81ea\u4e0d\u540c\u5bf9\u8c61<\/td><td><strong>x is not y<\/strong>&nbsp;\uff0c \u7c7b\u4f3c&nbsp;<strong>id(x) != id(y)<\/strong>\u3002\u5982\u679c\u5f15\u7528\u7684\u4e0d\u662f\u540c\u4e00\u4e2a\u5bf9\u8c61\u5219\u8fd4\u56de\u7ed3\u679c True\uff0c\u5426\u5219\u8fd4\u56de False\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u6ce8\uff1a<\/strong>&nbsp;<a href=\"https:\/\/www.runoob.com\/python\/python-func-id.html\" target=\"_blank\" rel=\"noreferrer noopener\">id()<\/a>&nbsp;\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u5185\u5b58\u5730\u5740\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u8eab\u4efd\u8fd0\u7b97\u7b26\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 20 b = 20 if ( a is b ): print (&#8220;1 &#8211; a \u548c b \u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;) else: print (&#8220;1 &#8211; a \u548c b \u6ca1\u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;) if ( id(a) == id(b) ): print (&#8220;2 &#8211; a \u548c b \u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;) else: print (&#8220;2 &#8211; a \u548c b \u6ca1\u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;) # \u4fee\u6539\u53d8\u91cf b \u7684\u503c b = 30 if ( a is b ): print (&#8220;3 &#8211; a \u548c b \u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;) else: print (&#8220;3 &#8211; a \u548c b \u6ca1\u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;) if ( a is not b ): print (&#8220;4 &#8211; a \u548c b \u6ca1\u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;) else: print (&#8220;4 &#8211; a \u548c b \u6709\u76f8\u540c\u7684\u6807\u8bc6&#8221;)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 - a \u548c b \u6709\u76f8\u540c\u7684\u6807\u8bc6\n2 - a \u548c b \u6709\u76f8\u540c\u7684\u6807\u8bc6\n3 - a \u548c b \u6ca1\u6709\u76f8\u540c\u7684\u6807\u8bc6\n4 - a \u548c b \u6ca1\u6709\u76f8\u540c\u7684\u6807\u8bc6<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>is \u4e0e == \u533a\u522b\uff1a<\/p>\n\n\n\n<p>is \u7528\u4e8e\u5224\u65ad\u4e24\u4e2a\u53d8\u91cf\u5f15\u7528\u5bf9\u8c61\u662f\u5426\u4e3a\u540c\u4e00\u4e2a\uff0c == \u7528\u4e8e\u5224\u65ad\u5f15\u7528\u53d8\u91cf\u7684\u503c\u662f\u5426\u76f8\u7b49\u3002<\/p>\n\n\n\n<p>&gt;&gt;&gt;a = [1, 2, 3] &gt;&gt;&gt; b = a &gt;&gt;&gt; b is a True &gt;&gt;&gt; b == a True &gt;&gt;&gt; b = a[:] &gt;&gt;&gt; b is a False &gt;&gt;&gt; b == a True<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ysf8\">Python\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7<\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u8868\u683c\u5217\u51fa\u4e86\u4ece\u6700\u9ad8\u5230\u6700\u4f4e\u4f18\u5148\u7ea7\u7684\u6240\u6709\u8fd0\u7b97\u7b26\uff0c \u76f8\u540c\u5355\u5143\u683c\u5185\u7684\u8fd0\u7b97\u7b26\u5177\u6709\u76f8\u540c\u4f18\u5148\u7ea7\u3002 \u8fd0\u7b97\u7b26\u5747\u6307\u4e8c\u5143\u8fd0\u7b97\uff0c\u9664\u975e\u7279\u522b\u6307\u51fa\u3002 \u76f8\u540c\u5355\u5143\u683c\u5185\u7684\u8fd0\u7b97\u7b26\u4ece\u5de6\u81f3\u53f3\u5206\u7ec4\uff08\u9664\u4e86\u5e42\u8fd0\u7b97\u662f\u4ece\u53f3\u81f3\u5de6\u5206\u7ec4\uff09\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td><code>(expressions...)<\/code>,<code>[expressions...]<\/code>,&nbsp;<code>{key:&nbsp;value...}<\/code>,&nbsp;<code>{expressions...}<\/code><\/td><td>\u5706\u62ec\u53f7\u7684\u8868\u8fbe\u5f0f<\/td><\/tr><tr><td><code>x[index]<\/code>,&nbsp;<code>x[index:index]<\/code>,&nbsp;<code>x(arguments...)<\/code>,&nbsp;<code>x.attribute<\/code><\/td><td>\u8bfb\u53d6\uff0c\u5207\u7247\uff0c\u8c03\u7528\uff0c\u5c5e\u6027\u5f15\u7528<\/td><\/tr><tr><td>await&nbsp;x<\/td><td>await \u8868\u8fbe\u5f0f<\/td><\/tr><tr><td><code>**<\/code><\/td><td>\u4e58\u65b9(\u6307\u6570)<\/td><\/tr><tr><td><code>+x<\/code>,&nbsp;<code>-x<\/code>,&nbsp;<code>~x<\/code><\/td><td>\u6b63\uff0c\u8d1f\uff0c\u6309\u4f4d\u975e NOT<\/td><\/tr><tr><td><code>*<\/code>,&nbsp;<code>@<\/code>,&nbsp;<code>\/<\/code>,&nbsp;<code>\/\/<\/code>,&nbsp;<code>%<\/code><\/td><td>\u4e58\uff0c\u77e9\u9635\u4e58\uff0c\u9664\uff0c\u6574\u9664\uff0c\u53d6\u4f59<\/td><\/tr><tr><td><code>+<\/code>,&nbsp;<code>-<\/code><\/td><td>\u52a0\u548c\u51cf<\/td><\/tr><tr><td><code>&lt;&lt;<\/code>,&nbsp;<code>&gt;&gt;<\/code><\/td><td>\u79fb\u4f4d<\/td><\/tr><tr><td><code>&amp;<\/code><\/td><td>\u6309\u4f4d\u4e0e AND<\/td><\/tr><tr><td><code>^<\/code><\/td><td>\u6309\u4f4d\u5f02\u6216 XOR<\/td><\/tr><tr><td><code>|<\/code><\/td><td>\u6309\u4f4d\u6216 OR<\/td><\/tr><tr><td><code>in,not&nbsp;in,&nbsp;is,is&nbsp;not,&nbsp;&lt;,&nbsp;&lt;=,&nbsp;&gt;,&nbsp;&gt;=,&nbsp;!=,&nbsp;==<\/code><\/td><td>\u6bd4\u8f83\u8fd0\u7b97\uff0c\u5305\u62ec\u6210\u5458\u68c0\u6d4b\u548c\u6807\u8bc6\u53f7\u68c0\u6d4b<\/td><\/tr><tr><td><code>not&nbsp;x<\/code><\/td><td>\u903b\u8f91\u975e NOT<\/td><\/tr><tr><td><code>and<\/code><\/td><td>\u903b\u8f91\u4e0e AND<\/td><\/tr><tr><td><code>or<\/code><\/td><td>\u903b\u8f91\u6216 OR<\/td><\/tr><tr><td><code>if&nbsp;--&nbsp;else<\/code><\/td><td>\u6761\u4ef6\u8868\u8fbe\u5f0f<\/td><\/tr><tr><td><code>lambda<\/code><\/td><td>lambda \u8868\u8fbe\u5f0f<\/td><\/tr><tr><td><code>:=<\/code><\/td><td>\u8d4b\u503c\u8868\u8fbe\u5f0f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6f14\u793a\u4e86Python\u6240\u6709\u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7\u7684\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = 20 b = 10 c = 15 d = 5 e = 0 e = (a + b) * c \/ d #( 30 * 15 ) \/ 5 print (&#8220;(a + b) * c \/ d \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a&#8221;, e) e = ((a + b) * c) \/ d # (30 * 15 ) \/ 5 print (&#8220;((a + b) * c) \/ d \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a&#8221;, e) e = (a + b) * (c \/ d) # (30) * (15\/5) print (&#8220;(a + b) * (c \/ d) \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a&#8221;, e) e = a + (b * c) \/ d # 20 + (150\/5) print (&#8220;a + (b * c) \/ d \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a&#8221;, e)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">(a + b) * c \/ d \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a 90.0\n((a + b) * c) \/ d \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a 90.0\n(a + b) * (c \/ d) \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a 90.0\na + (b * c) \/ d \u8fd0\u7b97\u7ed3\u679c\u4e3a\uff1a 50.0<\/pre>\n\n\n\n<p>and \u62e5\u6709\u66f4\u9ad8\u4f18\u5148\u7ea7:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b<\/h2>\n\n\n\n<p>x = True y = False z = False print(&#8220;\u60c5\u51b51\uff1a\u9ed8\u8ba4\u4f18\u5148\u7ea7\uff08\u5148\u7b97and\uff09&#8221;) if x or y and z: # \u7b49\u540c\u4e8e x or (y and z) print(&#8220;yes&#8221;) # \u4f1a\u8f93\u51fa else: print(&#8220;no&#8221;) print(&#8220;\\n\u60c5\u51b52\uff1a\u5f3a\u5236\u6539\u53d8\u4f18\u5148\u7ea7\uff08\u5148\u7b97or\uff09&#8221;) if (x or y) and z: # \u4eba\u4e3a\u6dfb\u52a0\u62ec\u53f7\u6539\u53d8\u987a\u5e8f print(&#8220;yes&#8221;) # \u4e0d\u4f1a\u8f93\u51fa else: print(&#8220;no&#8221;) # \u4f1a\u8f93\u51fa<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u5148\u8ba1\u7b97&nbsp;<strong>y and z<\/strong>&nbsp;\u5e76\u8fd4\u56de False \uff0c\u7136\u540e&nbsp;<strong>x or False<\/strong>&nbsp;\u8fd4\u56de True\uff0c\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u60c5\u51b51\uff1a\u9ed8\u8ba4\u4f18\u5148\u7ea7\uff08\u5148\u7b97and\uff09\nyes\n\n\u60c5\u51b52\uff1a\u5f3a\u5236\u6539\u53d8\u4f18\u5148\u7ea7\uff08\u5148\u7b97or\uff09\nno<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>\u6ce8\u610f\uff1a<\/strong>Python3 \u5df2\u4e0d\u652f\u6301&nbsp;<strong>&lt;&gt;<\/strong>&nbsp;\u8fd0\u7b97\u7b26\uff0c\u53ef\u4ee5\u4f7f\u7528&nbsp;<strong>!=<\/strong>&nbsp;\u4ee3\u66ff\uff0c\u5982\u679c\u4f60\u4e00\u5b9a\u8981\u4f7f\u7528\u8fd9\u79cd\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u7684\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&gt;&gt;&gt; from __future__ import barry_as_FLUFL\n&gt;&gt;&gt; 1 &lt;&gt; 2\nTrue<\/pre>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f\u8fd0\u7b97\u7b26\uff1f \u672c\u7ae0\u8282\u4e3b\u8981\u8bf4\u660e Python \u7684\u8fd0\u7b97\u7b26\u3002 \u4e3e\u4e2a\u7b80\u5355\u7684&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":476,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-587","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-1"],"views":649,"_links":{"self":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/comments?post=587"}],"version-history":[{"count":1,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/587\/revisions"}],"predecessor-version":[{"id":588,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/587\/revisions\/588"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media\/476"}],"wp:attachment":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media?parent=587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/categories?post=587"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/tags?post=587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}