{"id":1142,"date":"2025-04-12T20:06:29","date_gmt":"2025-04-12T12:06:29","guid":{"rendered":"https:\/\/www.sparkspace.top\/?p=1142"},"modified":"2025-04-12T20:12:49","modified_gmt":"2025-04-12T12:12:49","slug":"%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/www.sparkspace.top\/index.php\/%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/2025\/04\/12\/1142\/","title":{"rendered":"\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e00\u3001\u6838\u5fc3\u6570\u636e\u7c7b\u578b\u6982\u89c8<\/h3>\n\n\n\n<p>Python\u6570\u636e\u7c7b\u578b\u53ef\u5206\u4e3a<strong>\u53ef\u53d8\u7c7b\u578b<\/strong>\u4e0e<strong>\u4e0d\u53ef\u53d8\u7c7b\u578b<\/strong>\u4e24\u5927\u7c7b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e0d\u53ef\u53d8\u7c7b\u578b<\/strong>\uff1a\u6574\u6570\uff08<code>int<\/code>\uff09\u3001\u6d6e\u70b9\u6570\uff08<code>float<\/code>\uff09\u3001\u5b57\u7b26\u4e32\uff08<code>str<\/code>\uff09\u3001\u5e03\u5c14\u503c\uff08<code>bool<\/code>\uff09\u3001\u5143\u7ec4\uff08<code>tuple<\/code>\uff09<\/li>\n\n\n\n<li><strong>\u53ef\u53d8\u7c7b\u578b<\/strong>\uff1a\u5217\u8868\uff08<code>list<\/code>\uff09\u3001\u5b57\u5178\uff08<code>dict<\/code>\uff09\u3001\u96c6\u5408\uff08<code>set<\/code>\uff09<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8c\u3001\u57fa\u7840\u6570\u636e\u7c7b\u578b\u8865\u5145<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. \u5e03\u5c14\u578b\uff08<code>bool<\/code>\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b9a\u4e49<\/strong>\uff1a\u4ec5\u6709<code>True<\/code>\u548c<code>False<\/code>\u4e24\u4e2a\u503c\uff0c\u7528\u4e8e\u903b\u8f91\u5224\u65ad<\/li>\n\n\n\n<li><strong>\u672c\u8d28<\/strong>\uff1a\u662f\u6574\u578b\u7684\u5b50\u7c7b\uff08<code>True=1<\/code>\uff0c<code>False=0<\/code>\uff09<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>is_student = True\nprint(True + 1)  # \u8f93\u51fa2<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. \u5b57\u7b26\u4e32\u9ad8\u7ea7\u64cd\u4f5c<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8f6c\u4e49\u5b57\u7b26<\/strong>\uff1a<code>\\n<\/code>\uff08\u6362\u884c\uff09\u3001<code>\\t<\/code>\uff08\u5236\u8868\u7b26\uff09\u3001<code>\\\\<\/code>\uff08\u53cd\u659c\u6760\uff09<\/li>\n\n\n\n<li><strong>\u591a\u884c\u5b57\u7b26\u4e32<\/strong>\uff1a\u7528\u4e09\u5f15\u53f7<code>'''<\/code>\u6216<code>\"\"\"<\/code>\u5305\u88f9<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>poem = \"\"\"\u9759\u591c\u601d\n\u5e8a\u524d\u660e\u6708\u5149\uff0c\u7591\u662f\u5730\u4e0a\u971c\u3002\n\u4e3e\u5934\u671b\u660e\u6708\uff0c\u4f4e\u5934\u601d\u6545\u4e61\u3002\"\"\"<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e09\u3001\u7ec4\u5408\u6570\u636e\u7c7b\u578b\u8be6\u89e3<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. \u5217\u8868\uff08<code>list<\/code>\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u6027<\/strong>\uff1a\u6709\u5e8f\u53ef\u53d8\u5e8f\u5217\uff0c\u652f\u6301\u6df7\u5408\u6570\u636e\u7c7b\u578b<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># \u521b\u5efa\u4e0e\u64cd\u4f5c\nshopping_list = &#91;\"\u82f9\u679c\", \"\u725b\u5976\", 3.5]\nshopping_list.append(\"\u9762\u5305\")          # \u8ffd\u52a0\u5143\u7d20\nshopping_list.insert(1, \"\u9999\u8549\")       # \u63d2\u5165\u5143\u7d20\ndel shopping_list&#91;0]                 # \u5220\u9664\u5143\u7d20\nprint(shopping_list&#91;1:3])            # \u5207\u7247\u8f93\u51fa\uff1a&#91;\"\u725b\u5976\", 3.5]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. \u5143\u7ec4\uff08<code>tuple<\/code>\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u6027<\/strong>\uff1a\u6709\u5e8f\u4e0d\u53ef\u53d8\u5e8f\u5217\uff0c\u5e38\u7528\u4e8e\u56fa\u5b9a\u6570\u636e\u5b58\u50a8<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>coordinates = (39.9, 116.4)  \n# coordinates&#91;0] = 40.0  # \u62a5\u9519\uff01\u5143\u7ec4\u4e0d\u53ef\u4fee\u6539<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3. \u5b57\u5178\uff08<code>dict<\/code>\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u6027<\/strong>\uff1a\u952e\u503c\u5bf9\u96c6\u5408\uff0c\u952e\u5fc5\u987b\u552f\u4e00\u4e14\u4e0d\u53ef\u53d8<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>student = {\n    \"name\": \"\u5c0f\u660e\",\n    \"age\": 18,\n    \"courses\": &#91;\"\u6570\u5b66\", \"\u82f1\u8bed\"]\n}\nprint(student.get(\"age\"))     # \u83b7\u53d6\u503c \u2192 18\nstudent&#91;\"gender\"] = \"\u7537\"      # \u65b0\u589e\u952e\u503c\u5bf9<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4. \u96c6\u5408\uff08<code>set<\/code>\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7279\u6027<\/strong>\uff1a\u65e0\u5e8f\u552f\u4e00\u5143\u7d20\u96c6\u5408\uff0c\u652f\u6301\u4ea4\u5e76\u5dee\u8fd0\u7b97<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>unique_numbers = {1, 2, 2, 3}  # \u81ea\u52a8\u53bb\u91cd \u2192 {1, 2, 3}\na = {1, 2}; b = {2, 3}\nprint(a &amp; b)                   # \u4ea4\u96c6 \u2192 {2}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u56db\u3001\u6570\u636e\u7c7b\u578b\u5e94\u7528\u573a\u666f<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7c7b\u578b<\/th><th>\u5178\u578b\u573a\u666f<\/th><th>\u64cd\u4f5c\u6548\u7387<\/th><\/tr><\/thead><tbody><tr><td>\u5217\u8868<\/td><td>\u52a8\u6001\u6570\u636e\u5b58\u50a8\uff08\u5982\u8d2d\u7269\u6e05\u5355\u3001\u65e5\u5fd7\u8bb0\u5f55\uff09<\/td><td>\u67e5\u8be2O(n)<\/td><\/tr><tr><td>\u5143\u7ec4<\/td><td>\u56fa\u5b9a\u914d\u7f6e\u9879\uff08\u5982\u5750\u6807\u3001\u6570\u636e\u5e93\u5b57\u6bb5\u5b9a\u4e49\uff09<\/td><td>\u5185\u5b58\u5360\u7528\u5c11<\/td><\/tr><tr><td>\u5b57\u5178<\/td><td>\u5feb\u901f\u952e\u503c\u67e5\u8be2\uff08\u5982\u7528\u6237\u4fe1\u606f\u3001\u914d\u7f6e\u53c2\u6570\uff09<\/td><td>\u67e5\u8be2O(1)<\/td><\/tr><tr><td>\u96c6\u5408<\/td><td>\u53bb\u91cd\/\u96c6\u5408\u8fd0\u7b97\uff08\u5982\u7edf\u8ba1\u552f\u4e00IP\u3001\u5171\u540c\u597d\u53cb\uff09<\/td><td>\u6210\u5458\u68c0\u6d4bO(1)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e94\u3001\u7efc\u5408\u6848\u4f8b\u6f14\u793a<\/h3>\n\n\n\n<p><strong>\u5b66\u751f\u6210\u7ee9\u7ba1\u7406\u7cfb\u7edf<\/strong>\uff08\u7ed3\u5408\u5217\u8868+\u5b57\u5178\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>students = &#91;\n    {\"name\": \"\u5f20\u4e09\", \"scores\": &#91;85, 90]},\n    {\"name\": \"\u674e\u56db\", \"scores\": &#91;78, 92]}\n]\n\n# \u6dfb\u52a0\u65b0\u5b66\u751f\nstudents.append({\"name\": \"\u738b\u4e94\", \"scores\": &#91;88, 95]})\n\n# \u8ba1\u7b97\u5e73\u5747\u5206\nfor student in students:\n    avg = sum(student&#91;\"scores\"]) \/ len(student&#91;\"scores\"])\n    print(f\"{student&#91;'name']}\u5e73\u5747\u5206\uff1a{avg:.1f}\")<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u516d\u3001\u603b\u7ed3<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u91cd\u70b9\u603b\u7ed3<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5217\u8868\u9002\u5408\u9891\u7e41\u4fee\u6539\u7684\u5e8f\u5217\u6570\u636e\uff0c\u5b57\u5178\u9002\u5408\u5feb\u901f\u952e\u503c\u67e5\u8be2<\/li>\n\n\n\n<li>\u5143\u7ec4\u6bd4\u5217\u8868\u5185\u5b58\u5360\u7528\u66f4\u5c11\uff0c\u9002\u5408\u5b58\u50a8\u4e0d\u53d8\u6570\u636e<\/li>\n\n\n\n<li>\u96c6\u5408\u7684\u81ea\u52a8\u53bb\u91cd\u7279\u6027\u5728\u6570\u636e\u6e05\u6d17\u4e2d\u975e\u5e38\u5b9e\u7528<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6838\u5fc3\u6570\u636e\u7c7b\u578b\u6982\u89c8 Python\u6570\u636e\u7c7b\u578b\u53ef\u5206\u4e3a\u53ef\u53d8\u7c7b\u578b\u4e0e\u4e0d\u53ef\u53d8\u7c7b\u578b\u4e24\u5927\u7c7b\uff1a \u4e8c\u3001\u57fa\u7840\u6570\u636e\u7c7b\u578b\u8865\u5145 1. \u5e03\u5c14 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,1],"tags":[],"class_list":["post-1142","post","type-post","status-publish","format-standard","hentry","category-python","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/posts\/1142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/comments?post=1142"}],"version-history":[{"count":2,"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/posts\/1142\/revisions"}],"predecessor-version":[{"id":1146,"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/posts\/1142\/revisions\/1146"}],"wp:attachment":[{"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/media?parent=1142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/categories?post=1142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sparkspace.top\/index.php\/wp-json\/wp\/v2\/tags?post=1142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}