{"id":2726,"date":"2025-03-14T22:14:26","date_gmt":"2025-03-14T14:14:26","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=2726"},"modified":"2025-03-14T22:14:26","modified_gmt":"2025-03-14T14:14:26","slug":"python-3-%e8%bf%90%e7%ae%97%e7%ac%a6%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/03\/14\/python-3-%e8%bf%90%e7%ae%97%e7%ac%a6%e8%af%a6%e8%a7%a3\/","title":{"rendered":"Python 3 \u8fd0\u7b97\u7b26\u8be6\u89e3"},"content":{"rendered":"\n<p>Python 3 \u63d0\u4f9b\u4e86\u591a\u79cd<strong>\u8fd0\u7b97\u7b26\uff08Operators\uff09<\/strong>\uff0c\u7528\u4e8e\u6267\u884c\u6570\u5b66\u8ba1\u7b97\u3001\u6bd4\u8f83\u3001\u903b\u8f91\u5224\u65ad\u7b49\u64cd\u4f5c\u3002\u4e3b\u8981\u5305\u62ec <strong>\u7b97\u672f\u8fd0\u7b97\u7b26\u3001\u6bd4\u8f83\u8fd0\u7b97\u7b26\u3001\u8d4b\u503c\u8fd0\u7b97\u7b26\u3001\u903b\u8f91\u8fd0\u7b97\u7b26\u3001\u4f4d\u8fd0\u7b97\u7b26\u3001\u6210\u5458\u8fd0\u7b97\u7b26\u548c\u8eab\u4efd\u8fd0\u7b97\u7b26<\/strong>\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. \u7b97\u672f\u8fd0\u7b97\u7b26\uff08Arithmetic Operators\uff09<\/strong><\/h2>\n\n\n\n<p>\u7b97\u672f\u8fd0\u7b97\u7b26\u7528\u4e8e\u6267\u884c\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\uff0c\u5982\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u4e58\u6cd5\u7b49\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><th>\u7ed3\u679c<\/th><\/tr><\/thead><tbody><tr><td><code>+<\/code><\/td><td>\u52a0\u6cd5<\/td><td><code>5 + 3<\/code><\/td><td><code>8<\/code><\/td><\/tr><tr><td><code>-<\/code><\/td><td>\u51cf\u6cd5<\/td><td><code>10 - 4<\/code><\/td><td><code>6<\/code><\/td><\/tr><tr><td><code>*<\/code><\/td><td>\u4e58\u6cd5<\/td><td><code>6 * 2<\/code><\/td><td><code>12<\/code><\/td><\/tr><tr><td><code>\/<\/code><\/td><td>\u9664\u6cd5<\/td><td><code>9 \/ 2<\/code><\/td><td><code>4.5<\/code>\uff08\u7ed3\u679c\u662f<strong>\u6d6e\u70b9\u6570<\/strong>\uff09<\/td><\/tr><tr><td><code>\/\/<\/code><\/td><td>\u53d6\u6574\u9664<\/td><td><code>9 \/\/ 2<\/code><\/td><td><code>4<\/code>\uff08\u7ed3\u679c\u662f<strong>\u6574\u6570<\/strong>\uff0c\u5411\u4e0b\u53d6\u6574\uff09<\/td><\/tr><tr><td><code>%<\/code><\/td><td>\u53d6\u4f59<\/td><td><code>9 % 2<\/code><\/td><td><code>1<\/code>\uff08\u4f59\u6570\uff09<\/td><\/tr><tr><td><code>**<\/code><\/td><td>\u5e42\u8fd0\u7b97<\/td><td><code>2 ** 3<\/code><\/td><td><code>8<\/code>\uff082 \u7684 3 \u6b21\u65b9\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udccc <strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a, b = 10, 3\nprint(a + b)  # 13\nprint(a - b)  # 7\nprint(a * b)  # 30\nprint(a \/ b)  # 3.3333333333333335\nprint(a \/\/ b) # 3\nprint(a % b)  # 1\nprint(a ** b) # 1000<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. \u8d4b\u503c\u8fd0\u7b97\u7b26\uff08Assignment Operators\uff09<\/strong><\/h2>\n\n\n\n<p>\u8d4b\u503c\u8fd0\u7b97\u7b26\u7528\u4e8e\u7ed9\u53d8\u91cf\u8d4b\u503c\uff0c\u53ef\u4ee5\u7ed3\u5408\u8fd0\u7b97\u7b26\u8fdb\u884c\u590d\u5408\u8d4b\u503c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><th>\u7ed3\u679c<\/th><\/tr><\/thead><tbody><tr><td><code>=<\/code><\/td><td>\u8d4b\u503c<\/td><td><code>x = 5<\/code><\/td><td><code>x<\/code> \u53d8\u4e3a <code>5<\/code><\/td><\/tr><tr><td><code>+=<\/code><\/td><td>\u52a0\u6cd5\u8d4b\u503c<\/td><td><code>x += 3<\/code><\/td><td><code>x = x + 3<\/code><\/td><\/tr><tr><td><code>-=<\/code><\/td><td>\u51cf\u6cd5\u8d4b\u503c<\/td><td><code>x -= 2<\/code><\/td><td><code>x = x - 2<\/code><\/td><\/tr><tr><td><code>*=<\/code><\/td><td>\u4e58\u6cd5\u8d4b\u503c<\/td><td><code>x *= 4<\/code><\/td><td><code>x = x * 4<\/code><\/td><\/tr><tr><td><code>\/=<\/code><\/td><td>\u9664\u6cd5\u8d4b\u503c<\/td><td><code>x \/= 2<\/code><\/td><td><code>x = x \/ 2<\/code><\/td><\/tr><tr><td><code>\/\/=<\/code><\/td><td>\u53d6\u6574\u9664\u8d4b\u503c<\/td><td><code>x \/\/= 3<\/code><\/td><td><code>x = x \/\/ 3<\/code><\/td><\/tr><tr><td><code>%=<\/code><\/td><td>\u53d6\u4f59\u8d4b\u503c<\/td><td><code>x %= 2<\/code><\/td><td><code>x = x % 2<\/code><\/td><\/tr><tr><td><code>**=<\/code><\/td><td>\u5e42\u8d4b\u503c<\/td><td><code>x **= 2<\/code><\/td><td><code>x = x ** 2<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udccc <strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>x = 10\nx += 5  # x = x + 5\nprint(x)  # 15<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. \u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08Comparison Operators\uff09<\/strong><\/h2>\n\n\n\n<p>\u6bd4\u8f83\u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u503c\uff0c\u8fd4\u56de <strong><code>True<\/code> \u6216 <code>False<\/code><\/strong>\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><th>\u7ed3\u679c<\/th><\/tr><\/thead><tbody><tr><td><code>==<\/code><\/td><td>\u7b49\u4e8e<\/td><td><code>5 == 5<\/code><\/td><td><code>True<\/code><\/td><\/tr><tr><td><code>!=<\/code><\/td><td>\u4e0d\u7b49\u4e8e<\/td><td><code>5 != 3<\/code><\/td><td><code>True<\/code><\/td><\/tr><tr><td><code>&gt;<\/code><\/td><td>\u5927\u4e8e<\/td><td><code>7 &gt; 4<\/code><\/td><td><code>True<\/code><\/td><\/tr><tr><td><code>&lt;<\/code><\/td><td>\u5c0f\u4e8e<\/td><td><code>3 &lt; 8<\/code><\/td><td><code>True<\/code><\/td><\/tr><tr><td><code>&gt;=<\/code><\/td><td>\u5927\u4e8e\u7b49\u4e8e<\/td><td><code>5 &gt;= 5<\/code><\/td><td><code>True<\/code><\/td><\/tr><tr><td><code>&lt;=<\/code><\/td><td>\u5c0f\u4e8e\u7b49\u4e8e<\/td><td><code>6 &lt;= 9<\/code><\/td><td><code>True<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udccc <strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a, b = 10, 5\nprint(a == b)  # False\nprint(a != b)  # True\nprint(a &gt; b)   # True\nprint(a &lt; b)   # False\nprint(a &gt;= b)  # True\nprint(a &lt;= b)  # False<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4. \u903b\u8f91\u8fd0\u7b97\u7b26\uff08Logical Operators\uff09<\/strong><\/h2>\n\n\n\n<p>\u903b\u8f91\u8fd0\u7b97\u7b26\u7528\u4e8e <strong>\u5e03\u5c14\uff08Boolean\uff09\u8fd0\u7b97<\/strong>\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><th>\u7ed3\u679c<\/th><\/tr><\/thead><tbody><tr><td><code>and<\/code><\/td><td>\u903b\u8f91\u4e0e<\/td><td><code>True and False<\/code><\/td><td><code>False<\/code><\/td><\/tr><tr><td><code>or<\/code><\/td><td>\u903b\u8f91\u6216<\/td><td><code>True or False<\/code><\/td><td><code>True<\/code><\/td><\/tr><tr><td><code>not<\/code><\/td><td>\u903b\u8f91\u975e<\/td><td><code>not True<\/code><\/td><td><code>False<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udccc <strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a, b = True, False\nprint(a and b)  # False\nprint(a or b)   # True\nprint(not a)    # False<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5. \u4f4d\u8fd0\u7b97\u7b26\uff08Bitwise Operators\uff09<\/strong><\/h2>\n\n\n\n<p>\u4f4d\u8fd0\u7b97\u7b26\u7528\u4e8e\u6309\u4f4d\u8ba1\u7b97\u6574\u6570\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><th>\u7ed3\u679c\uff08\u4e8c\u8fdb\u5236\uff09<\/th><th>\u7ed3\u679c\uff08\u5341\u8fdb\u5236\uff09<\/th><\/tr><\/thead><tbody><tr><td><code>&amp;<\/code><\/td><td>\u6309\u4f4d\u4e0e<\/td><td><code>5 &amp; 3<\/code><\/td><td><code>0b0001<\/code><\/td><td><code>1<\/code><\/td><\/tr><tr><td><code>|<\/code><\/td><td>\u6309\u4f4d\u6216<\/td><td><code>5 | 3<\/code><\/td><td><code>0b0111<\/code><\/td><td><code>7<\/code><\/td><\/tr><tr><td><code>^<\/code><\/td><td>\u6309\u4f4d\u5f02\u6216<\/td><td><code>5 ^ 3<\/code><\/td><td><code>0b0110<\/code><\/td><td><code>6<\/code><\/td><\/tr><tr><td><code>~<\/code><\/td><td>\u6309\u4f4d\u53d6\u53cd<\/td><td><code>~5<\/code><\/td><td><code>0b...1010<\/code><\/td><td><code>-6<\/code><\/td><\/tr><tr><td><code>&lt;&lt;<\/code><\/td><td>\u5de6\u79fb<\/td><td><code>5 &lt;&lt; 1<\/code><\/td><td><code>0b1010<\/code><\/td><td><code>10<\/code><\/td><\/tr><tr><td><code>&gt;&gt;<\/code><\/td><td>\u53f3\u79fb<\/td><td><code>5 &gt;&gt; 1<\/code><\/td><td><code>0b0010<\/code><\/td><td><code>2<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udccc <strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a, b = 5, 3  # 5 = 0b0101, 3 = 0b0011\nprint(a &amp; b)  # 1\nprint(a | b)  # 7\nprint(a ^ b)  # 6\nprint(~a)     # -6\nprint(a &lt;&lt; 1) # 10\nprint(a &gt;&gt; 1) # 2<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>6. \u6210\u5458\u8fd0\u7b97\u7b26\uff08Membership Operators\uff09<\/strong><\/h2>\n\n\n\n<p>\u7528\u4e8e\u68c0\u67e5\u67d0\u4e2a\u503c\u662f\u5426\u5b58\u5728\u4e8e\u67d0\u4e2a\u5e8f\u5217\uff08\u5982\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\u7b49\uff09\u4e2d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><th>\u7ed3\u679c<\/th><\/tr><\/thead><tbody><tr><td><code>in<\/code><\/td><td>\u662f\u5426\u5b58\u5728<\/td><td><code>'a' in 'apple'<\/code><\/td><td><code>True<\/code><\/td><\/tr><tr><td><code>not in<\/code><\/td><td>\u662f\u5426\u4e0d\u5b58\u5728<\/td><td><code>3 not in [1, 2, 4]<\/code><\/td><td><code>True<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udccc <strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nums = &#91;1, 2, 3, 4, 5]\nprint(3 in nums)  # True\nprint(6 not in nums)  # True<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>7. \u8eab\u4efd\u8fd0\u7b97\u7b26\uff08Identity Operators\uff09<\/strong><\/h2>\n\n\n\n<p>\u7528\u4e8e\u6bd4\u8f83\u4e24\u4e2a\u5bf9\u8c61\u7684\u5185\u5b58\u5730\u5740\u662f\u5426\u76f8\u540c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u8fd0\u7b97\u7b26<\/th><th>\u8bf4\u660e<\/th><th>\u793a\u4f8b<\/th><th>\u7ed3\u679c<\/th><\/tr><\/thead><tbody><tr><td><code>is<\/code><\/td><td>\u662f\u5426\u662f\u540c\u4e00\u5bf9\u8c61<\/td><td><code>a is b<\/code><\/td><td><code>True\/False<\/code><\/td><\/tr><tr><td><code>is not<\/code><\/td><td>\u662f\u5426\u4e0d\u662f\u540c\u4e00\u5bf9\u8c61<\/td><td><code>a is not b<\/code><\/td><td><code>True\/False<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udccc <strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a = &#91;1, 2, 3]\nb = a\nc = &#91;1, 2, 3]\n\nprint(a is b)  # True (b \u76f4\u63a5\u6307\u5411 a)\nprint(a is c)  # False (c \u662f\u4e00\u4e2a\u65b0\u7684\u5217\u8868)\nprint(a == c)  # True (\u503c\u76f8\u7b49)<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u603b\u7ed3<\/strong><\/h2>\n\n\n\n<p>Python 3 \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u8fd0\u7b97\u7b26\uff0c\u638c\u63e1\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u80fd\u66f4\u9ad8\u6548\u5730\u7f16\u5199\u4ee3\u7801\u3002\u53ef\u4ee5\u7ed3\u5408 <strong>\u7b97\u672f\u3001\u8d4b\u503c\u3001\u6bd4\u8f83\u3001\u903b\u8f91\u3001\u4f4d\u8fd0\u7b97\u3001\u6210\u5458\u548c\u8eab\u4efd\u8fd0\u7b97\u7b26<\/strong> \u5728\u4e0d\u540c\u573a\u666f\u4e0b\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python 3 \u63d0\u4f9b\u4e86\u591a\u79cd\u8fd0\u7b97\u7b26\uff08Operators\uff09\uff0c\u7528\u4e8e\u6267\u884c\u6570\u5b66\u8ba1\u7b97\u3001\u6bd4\u8f83\u3001\u903b\u8f91\u5224\u65ad\u7b49\u64cd\u4f5c\u3002\u4e3b\u8981\u5305\u62ec \u7b97 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2727,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79],"tags":[],"class_list":["post-2726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-3-"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=2726"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2726\/revisions"}],"predecessor-version":[{"id":2728,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/2726\/revisions\/2728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media\/2727"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=2726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=2726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=2726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}