{"id":2037,"date":"2026-07-13T09:20:15","date_gmt":"2026-07-13T01:20:15","guid":{"rendered":"https:\/\/wp.kcra.org.hk\/?p=2037"},"modified":"2026-07-13T09:20:15","modified_gmt":"2026-07-13T01:20:15","slug":"python-%e5%84%aa%e9%9b%85%e7%9a%84%e8%ae%8a%e6%95%b8%e4%ba%a4%e6%8f%9b%ef%bc%9aa-b-b-a-%e7%9a%84%e5%ba%95%e5%b1%a4%e5%85%83%e7%b5%84%e6%8b%86%e5%8c%85%e6%a9%9f%e5%88%b6","status":"publish","type":"post","link":"https:\/\/wp.kcra.org.hk\/?p=2037","title":{"rendered":"Python: \u512a\u96c5\u7684\u8b8a\u6578\u4ea4\u63db\uff1aa, b = b, a \u7684\u5e95\u5c64\u5143\u7d44\u62c6\u5305\u6a5f\u5236"},"content":{"rendered":"\n<p><strong>\u50b3\u7d71\u8a9e\u8a00\u7684\u300c\u66ab\u5b58\u8b8a\u6578\u300d<\/strong><\/p>\n<p>\u5728\u5927\u591a\u6578\u7a0b\u5f0f\u8a9e\u8a00\u4e2d\uff0c\u5982\u679c\u4f60\u60f3\u628a\u8b8a\u6578 a\uff08\u503c\u70ba 5\uff09\u548c\u8b8a\u6578 b\uff08\u503c\u70ba 10\uff09\u7684\u5167\u5bb9\u4e92\u76f8\u4ea4\u63db\uff0c\u4f60\u4e0d\u80fd\u76f4\u63a5\u5beb a = b; b = a\uff08\u9019\u6a23 a \u8b8a\u6210 10 \u5f8c\uff0cb = a \u5c31\u6703\u8b93 b \u4e5f\u8b8a\u6210 10\uff0c\u539f\u672c 5 \u7684\u8cc7\u6599\u5c31\u907a\u5931\u4e86\uff09\u3002\u56e0\u6b64\u4f60\u5fc5\u9808\u5f15\u9032\u7b2c\u4e09\u500b\u81e8\u6642\u66ab\u5b58\u8b8a\u6578 temp\uff1a<\/p>\n\n\n\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 100%;\">\n<h4><strong>C<\/strong><\/h4>\n<p>int temp = a;<\/p>\n<p>a = b;<\/p>\n<p>b = temp;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\n<p><strong>Python <\/strong><strong>\u7684\u4e00\u884c\u641e\u5b9a<\/strong><\/p>\n<p>\u5728 Python \u4e2d\uff0c\u4f60\u53ea\u9700\u8981\u4e00\u884c\u9b54\u6cd5\u822c\u7684\u4ee3\u78bc\uff1a<\/p>\n\n\n\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 100%;\">\n<h4><strong>Python<\/strong><\/h4>\n<p>a, b = b, a<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\n<p><strong>\u5e95\u5c64\u904b\u4f5c\u539f\u7406\uff08Tuple Unpacking<\/strong><strong>\uff09<\/strong><\/p>\n<p>\u9019\u4e26\u4e0d\u662f\u8a9e\u6cd5\u7cd6\u90a3\u9ebc\u7c21\u55ae\uff0cPython \u5728\u5e95\u5c64\u5176\u5be6\u904b\u7528\u4e86<strong>\u5143\u7d44\uff08<\/strong><strong>Tuple<\/strong><strong>\uff09\u7684\u5c01\u88dd\u8207\u62c6\u5305\u6a5f\u5236<\/strong>\uff1a<\/p>\n<ol>\n<li><strong>\u53f3\u5074\u5c01\u88dd\uff08Packing<\/strong><strong>\uff09<\/strong>\uff1aPython \u6703\u5148\u5c07\u7b49\u865f\u53f3\u908a\u7684 b, a \u653e\u5165\u8a18\u61b6\u9ad4\u4e2d\uff0c\u81ea\u52d5\u6253\u5305\u6210\u4e00\u500b\u7121\u540d\u7684\u5143\u7d44 (b, a)\u3002\u6b64\u6642\u88e1\u9762\u7684\u503c\u5df2\u7d93\u88ab\u56fa\u5b9a\u4e0b\u4f86\uff08\u4f8b\u5982 (10, 5)\uff09\u3002<\/li>\n<li><strong>\u5de6\u5074\u62c6\u5305\uff08Unpacking<\/strong><strong>\uff09<\/strong>\uff1a\u63a5\u8457\uff0cPython \u6703\u628a\u9019\u500b\u5143\u7d44\u5167\u7684\u4f4d\u7f6e\uff0c\u4f9d\u5e8f\u6307\u6d3e\u7d66\u7b49\u865f\u5de6\u908a\u7684\u8b8a\u6578 a \u548c b\u3002<br \/>\u7531\u65bc\u9019\u500b\u904e\u7a0b\u662f\u5728\u540c\u4e00\u500b\u6307\u4ee4\u9031\u671f\u4e2d\u900f\u904e CPython \u89e3\u8b6f\u5668\u5167\u90e8\u4e00\u6b21\u6027\u5b8c\u6210\uff0c\u56e0\u6b64\u5b8c\u5168\u4e0d\u9700\u8981\u5de5\u7a0b\u5e2b\u624b\u52d5\u53bb\u5beb\u66ab\u5b58\u8b8a\u6578\uff0c\u4e0d\u50c5\u7a0b\u5f0f\u78bc\u6975\u5176\u512a\u96c5\uff0c\u57f7\u884c\u6548\u7387\u4e5f\u975e\u5e38\u597d\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u50b3\u7d71\u8a9e\u8a00\u7684\u300c\u66ab\u5b58\u8b8a\u6578\u300d \u5728\u5927\u591a\u6578\u7a0b\u5f0f\u8a9e\u8a00\u4e2d\uff0c\u5982\u679c\u4f60\u60f3\u628a\u8b8a\u6578 a\uff08\u503c\u70ba 5\uff09\u548c\u8b8a\u6578 b\uff08\u503c\u70ba 10\uff09\u7684\u5167\u5bb9\u4e92\u76f8\u4ea4 &hellip; <a href=\"https:\/\/wp.kcra.org.hk\/?p=2037\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">Python: \u512a\u96c5\u7684\u8b8a\u6578\u4ea4\u63db\uff1aa, b = b, a \u7684\u5e95\u5c64\u5143\u7d44\u62c6\u5305\u6a5f\u5236<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":50,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-2037","post","type-post","status-publish","format-standard","hentry","category-9"],"_links":{"self":[{"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=\/wp\/v2\/posts\/2037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2037"}],"version-history":[{"count":1,"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=\/wp\/v2\/posts\/2037\/revisions"}],"predecessor-version":[{"id":2038,"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=\/wp\/v2\/posts\/2037\/revisions\/2038"}],"wp:attachment":[{"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.kcra.org.hk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}