{"id":45,"date":"2023-10-14T21:23:01","date_gmt":"2023-10-14T13:23:01","guid":{"rendered":"https:\/\/leezp.top\/?p=45"},"modified":"2024-10-15T13:38:24","modified_gmt":"2024-10-15T05:38:24","slug":"%e4%bd%bf%e7%94%a8python%e5%81%9a%e7%ac%94%e8%af%95%e9%a2%98%e7%9a%84%e6%8a%80%e5%b7%a7%ef%bc%88%e7%89%9b%e5%ae%a2%e7%bd%91acm%e6%a8%a1%e5%bc%8f%ef%bc%89","status":"publish","type":"post","link":"https:\/\/leezp.top\/?p=45","title":{"rendered":"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09"},"content":{"rendered":"\n<p class=\"has-medium-font-size wp-block-paragraph\">\u7528Python\u505a\u673a\u8bd5\u9898\u7684\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8f93\u5165\u8f93\u51fa\u90e8\u5206<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import sys\n\n# \u5b9a\u884c\u8f93\u5165\nfor i in range(n):\n    line = sys.stdin.readline().strip() # \u6bcf\u6b21\u4ec5\u8bfb\u53d6\u4e00\u884c\uff0c\u522b\u5fd8strip\u53bb\u9664\u6700\u540e\u56de\u8f66\n    \n# \u4e0d\u5b9a\u884c\u8f93\u5165\nfor line in sys.stdin: #\u4f1a\u4e00\u76f4\u8bfb\u5230\u8f93\u5165\u7ed3\u675f\uff0c\u522b\u5fd8strip\u53bb\u9664\u6700\u540e\u56de\u8f66\n    str_in = line.strip()\n\n# input\u8f93\u5165\nfor i in range(n):\n    str_item = input().strip()  # input()\u8bfb\u53d6\u5230\u7a7a\u683c\u548c\u56de\u8f66\u90fd\u8ba4\u4e3a\u662f\u5206\u9694\u7b26\uff0c\u522b\u5fd8strip\u53bb\u9664\u6700\u540e\u56de\u8f66\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> sys<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5b9a\u884c\u8f93\u5165<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(n):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    line = sys.stdin.readline().strip() <\/span><span style=\"color: #6A9955\"># \u6bcf\u6b21\u4ec5\u8bfb\u53d6\u4e00\u884c\uff0c\u522b\u5fd8strip\u53bb\u9664\u6700\u540e\u56de\u8f66<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4e0d\u5b9a\u884c\u8f93\u5165<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> line <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> sys.stdin: <\/span><span style=\"color: #6A9955\">#\u4f1a\u4e00\u76f4\u8bfb\u5230\u8f93\u5165\u7ed3\u675f\uff0c\u522b\u5fd8strip\u53bb\u9664\u6700\u540e\u56de\u8f66<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    str_in = line.strip()<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># input\u8f93\u5165<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(n):<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    str_item = <\/span><span style=\"color: #DCDCAA\">input<\/span><span style=\"color: #D4D4D4\">().strip()  <\/span><span style=\"color: #6A9955\"># input()\u8bfb\u53d6\u5230\u7a7a\u683c\u548c\u56de\u8f66\u90fd\u8ba4\u4e3a\u662f\u5206\u9694\u7b26\uff0c\u522b\u5fd8strip\u53bb\u9664\u6700\u540e\u56de\u8f66<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5904\u7406\u90e8\u5206<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);--cbp-line-highlight-color:rgba(234, 191, 191, 0.2);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u79fb\u9664\u5b57\u7b26\u4e32\u5934\u5c3e\u6307\u5b9a\u7684\u5b57\u7b26\u6216\u5b57\u7b26\u5e8f\u5217(\u9ed8\u8ba4\u4e3a\u7a7a\u683c\u6216\u6362\u884c\u7b26)\uff0c\u8fd4\u56de\u751f\u6210\u7684\u65b0\u5b57\u7b26\u4e32\nstr1 = str_in.strip()\n# \u53bb\u9664\u9996\u5c3e\u5b57\u7b26\u4e3201\nstr2 = str_in.strip(&quot;01&quot;);  \n\n# \u901a\u8fc7\u6307\u5b9a\u5206\u9694\u7b26\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u5207\u7247\uff0c\u8fd4\u56de\u5206\u5272\u540e\u7684\u5b57\u7b26\u4e32\u5217\u8868\nstr_list = str_in.split(&quot; &quot;) \n\n# \u4f7f\u7528map\u5bf9\u5217\u8868\u8fdb\u884c\u5904\u7406,\u4f1a\u6839\u636e\u63d0\u4f9b\u7684\u51fd\u6570\u5bf9\u6307\u5b9a\u5e8f\u5217\u505a\u6620\u5c04\uff0c\u5728Python3\u4e2d\u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u6545\u9700\u8981\u518d\u8f6c\u6362\u6210\u5217\u8868\nint_list1 = list(map(int,str_list))\n# \u4e5f\u53ef\u4ee5\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u6765\u8fdb\u884c\u66f4\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u8f6c\u6362\u4e3a\u6574\u6570\u540e\u518d\u5e73\u65b9\nint_list2 = list(map(lambda x:int(x)**2, str_list))\n\n# \u8fdb\u5236\u8f6c\u6362\uff1a\u5176\u4ed6\u8fdb\u5236\u5b57\u7b26\u4e32\u8f6c\u5341\u8fdb\u5236\nint1 = int('0xA',16) # 10\nint2 = int('1001',2) # 9\nint3 = int('17',8) # 15\n\n# \u8fdb\u5236\u8f6c\u6362\uff1a\u5341\u8fdb\u5236\u8f6c\u5176\u4ed6\u8fdb\u5236\u5b57\u7b26\u4e32\nstr_hex = hex(15) # 0xf\nstr_bin = bin(2) # 0b10\nstr_oct = oct(7) # 0o7\n\n#\u5bf9\u6570\nimport math\nmath.log(2.7) #\u5e95\u6570\u9ed8\u8ba4e\n\n# ASCII\u7801\u4e0e\u5b57\u7b26\u76f8\u4e92\u8f6c\u6362: ord()\u83b7\u53d6ASCII\u7801\uff0cchr()\u8f6c\u5b57\u7b26\nprint(&quot;a\u7684ASCII\u7801\u4e3a&quot;, ord('a'))\nprint(&quot;101\u5bf9\u5e94\u7684\u5b57\u7b26\u4e3a&quot;, chr(101))\n\n# \u6d6e\u70b9\u6570\u8f6c\u6574\u578b\n\n# int \u54110\u53d6\u6574\nint(-0.5)  # 0\nint(-0.9) # 0\nint(0.5)  # 0\nint(0.9) # 0\n\n\n# round \u56db\u820d\u516d\u5165\uff0c\u4e94\u5411\u5076\u53d6\u6574\nround(0.5)  # 0\nround(0.6)  # 1\nround(1.5)  # 2\nround(-2.5) # -2\nround(-1.4) # -1\nround(-1.6) # -2\n\nimport math\n# math.floor \u5411\u4e0b\u53d6\u6574\uff08\u5411\u6570\u8f74\u8d1f\u65b9\u5411\uff09\uff08\u4e0e\u6574\u9664\u7b26\u53f7\/\/\u4e00\u6837\uff09\nmath.floor(0.9)  # 0\nmath.floor(-0.9)  # -1\n\n# math.ceil \u5411\u4e0a\u53d6\u6574\uff08\u5411\u6570\u8f74\u6b63\u65b9\u5411\uff09\nmath.ceil(0.3) # 1\nmath.ceil(0.5)  # 1\nmath.ceil(-0.5)  # 0\nmath.ceil(-0.9)  # 0\n\n\n# \u8f93\u5165\u65f6\u8f6c\u6362\u793a\u4f8b1\uff1a\u5c06\u5b57\u7b26\u4e32\u201c1 2 3 4\u201d\u8f6c\u6362\u4e3a\u6574\u578b\u5217\u8868\nfor line in sys.stdin:\n    a = list(map(int,line.strip().split(&quot; &quot;))) # [1, 2, 3, 4]\n    \n# \u8f93\u5165\u65f6\u8f6c\u6362\u793a\u4f8b2\uff1a\u5c06\u5b57\u7b26\u4e32\u201c1 2 3 4\u201d\u5185\u7684\u6570\u5b57\u5e73\u65b9\u540e\uff0c\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\uff0c\u5f97\u5230\u5217\u8868\nfor line in sys.stdin:\n    a = list(map(lambda x:hex(int(x)**2),line.strip().split(&quot; &quot;))) \n    #['0x1', '0x4', '0x9', '0x10']\n    \" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># \u79fb\u9664\u5b57\u7b26\u4e32\u5934\u5c3e\u6307\u5b9a\u7684\u5b57\u7b26\u6216\u5b57\u7b26\u5e8f\u5217(\u9ed8\u8ba4\u4e3a\u7a7a\u683c\u6216\u6362\u884c\u7b26)\uff0c\u8fd4\u56de\u751f\u6210\u7684\u65b0\u5b57\u7b26\u4e32<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">str1 = str_in.strip()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u53bb\u9664\u9996\u5c3e\u5b57\u7b26\u4e3201<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">str2 = str_in.strip(<\/span><span style=\"color: #CE9178\">&quot;01&quot;<\/span><span style=\"color: #D4D4D4\">);  <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u901a\u8fc7\u6307\u5b9a\u5206\u9694\u7b26\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u5207\u7247\uff0c\u8fd4\u56de\u5206\u5272\u540e\u7684\u5b57\u7b26\u4e32\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">str_list = str_in.split(<\/span><span style=\"color: #CE9178\">&quot; &quot;<\/span><span style=\"color: #D4D4D4\">) <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4f7f\u7528map\u5bf9\u5217\u8868\u8fdb\u884c\u5904\u7406,\u4f1a\u6839\u636e\u63d0\u4f9b\u7684\u51fd\u6570\u5bf9\u6307\u5b9a\u5e8f\u5217\u505a\u6620\u5c04\uff0c\u5728Python3\u4e2d\u8fd4\u56de\u8fed\u4ee3\u5668\uff0c\u6545\u9700\u8981\u518d\u8f6c\u6362\u6210\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">int_list1 = <\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">map<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">,str_list))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4e5f\u53ef\u4ee5\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u6765\u8fdb\u884c\u66f4\u590d\u6742\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u8f6c\u6362\u4e3a\u6574\u6570\u540e\u518d\u5e73\u65b9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">int_list2 = <\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">map<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\">:<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(x)**<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, str_list))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u8fdb\u5236\u8f6c\u6362\uff1a\u5176\u4ed6\u8fdb\u5236\u5b57\u7b26\u4e32\u8f6c\u5341\u8fdb\u5236<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">int1 = <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;0xA&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">16<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">int2 = <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;1001&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">int3 = <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;17&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">8<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 15<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u8fdb\u5236\u8f6c\u6362\uff1a\u5341\u8fdb\u5236\u8f6c\u5176\u4ed6\u8fdb\u5236\u5b57\u7b26\u4e32<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">str_hex = <\/span><span style=\"color: #DCDCAA\">hex<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">15<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 0xf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">str_bin = <\/span><span style=\"color: #DCDCAA\">bin<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 0b10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">str_oct = <\/span><span style=\"color: #DCDCAA\">oct<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">7<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 0o7<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u5bf9\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> math<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">math.log(<\/span><span style=\"color: #B5CEA8\">2.7<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\">#\u5e95\u6570\u9ed8\u8ba4e<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># ASCII\u7801\u4e0e\u5b57\u7b26\u76f8\u4e92\u8f6c\u6362: ord()\u83b7\u53d6ASCII\u7801\uff0cchr()\u8f6c\u5b57\u7b26<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;a\u7684ASCII\u7801\u4e3a&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #DCDCAA\">ord<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;a&#39;<\/span><span style=\"color: #D4D4D4\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;101\u5bf9\u5e94\u7684\u5b57\u7b26\u4e3a&quot;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #DCDCAA\">chr<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">101<\/span><span style=\"color: #D4D4D4\">))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u6d6e\u70b9\u6570\u8f6c\u6574\u578b<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># int \u54110\u53d6\u6574<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(-<\/span><span style=\"color: #B5CEA8\">0.5<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(-<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">0.5<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># round \u56db\u820d\u516d\u5165\uff0c\u4e94\u5411\u5076\u53d6\u6574<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">round<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">0.5<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">round<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">0.6<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">round<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">1.5<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">round<\/span><span style=\"color: #D4D4D4\">(-<\/span><span style=\"color: #B5CEA8\">2.5<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># -2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">round<\/span><span style=\"color: #D4D4D4\">(-<\/span><span style=\"color: #B5CEA8\">1.4<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># -1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">round<\/span><span style=\"color: #D4D4D4\">(-<\/span><span style=\"color: #B5CEA8\">1.6<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># -2<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> math<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># math.floor \u5411\u4e0b\u53d6\u6574\uff08\u5411\u6570\u8f74\u8d1f\u65b9\u5411\uff09\uff08\u4e0e\u6574\u9664\u7b26\u53f7\/\/\u4e00\u6837\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">math.floor(<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">math.floor(-<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># -1<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># math.ceil \u5411\u4e0a\u53d6\u6574\uff08\u5411\u6570\u8f74\u6b63\u65b9\u5411\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">math.ceil(<\/span><span style=\"color: #B5CEA8\">0.3<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># 1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">math.ceil(<\/span><span style=\"color: #B5CEA8\">0.5<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">math.ceil(-<\/span><span style=\"color: #B5CEA8\">0.5<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">math.ceil(-<\/span><span style=\"color: #B5CEA8\">0.9<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># 0<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u8f93\u5165\u65f6\u8f6c\u6362\u793a\u4f8b1\uff1a\u5c06\u5b57\u7b26\u4e32\u201c1 2 3 4\u201d\u8f6c\u6362\u4e3a\u6574\u578b\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> line <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> sys.stdin:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    a = <\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">map<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">,line.strip().split(<\/span><span style=\"color: #CE9178\">&quot; &quot;<\/span><span style=\"color: #D4D4D4\">))) <\/span><span style=\"color: #6A9955\"># [1, 2, 3, 4]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u8f93\u5165\u65f6\u8f6c\u6362\u793a\u4f8b2\uff1a\u5c06\u5b57\u7b26\u4e32\u201c1 2 3 4\u201d\u5185\u7684\u6570\u5b57\u5e73\u65b9\u540e\uff0c\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\uff0c\u5f97\u5230\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> line <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> sys.stdin:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    a = <\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">map<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\">:<\/span><span style=\"color: #DCDCAA\">hex<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(x)**<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">),line.strip().split(<\/span><span style=\"color: #CE9178\">&quot; &quot;<\/span><span style=\"color: #D4D4D4\">))) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #6A9955\">#[&#39;0x1&#39;, &#39;0x4&#39;, &#39;0x9&#39;, &#39;0x10&#39;]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u6392\u5e8f<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"#Python3\u4e2dlist.sort()\u548csorted()\u4e2d\u7684cmp\u53c2\u6570\u5df2\u7ecf\u88ab\u79fb\u9664\uff0c\u6b64\u5904\u5373\u4e3aPython3\n\n#list.sort()\u6ca1\u6709\u8fd4\u56de\u503c\uff0c\u81ea\u8eab\u6392\u5e8f\nlist_in.sort(key=None, reverse=False) \n\n#sorted()\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\uff0c\u53c2\u6570\u63a5\u53d7\u4efb\u4f55\u53ef\u8fed\u4ee3\u5bf9\u8c61\nsorted_list = sorted(list_in, key=None, reverse=False)  \n\n#\u6309key\u6392\u5e8f\u4f7f\u7528\u4f8b\u5b50\uff1a\nlist1.sort(key=lambda x:x[1])\nlist1_sorted = sorted(list1, key=lambda x:x[1])\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">#Python3\u4e2dlist.sort()\u548csorted()\u4e2d\u7684cmp\u53c2\u6570\u5df2\u7ecf\u88ab\u79fb\u9664\uff0c\u6b64\u5904\u5373\u4e3aPython3<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#list.sort()\u6ca1\u6709\u8fd4\u56de\u503c\uff0c\u81ea\u8eab\u6392\u5e8f<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">list_in.sort(<\/span><span style=\"color: #9CDCFE\">key<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">None<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">reverse<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">False<\/span><span style=\"color: #D4D4D4\">) <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#sorted()\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\uff0c\u53c2\u6570\u63a5\u53d7\u4efb\u4f55\u53ef\u8fed\u4ee3\u5bf9\u8c61<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">sorted_list = <\/span><span style=\"color: #DCDCAA\">sorted<\/span><span style=\"color: #D4D4D4\">(list_in, <\/span><span style=\"color: #9CDCFE\">key<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">None<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">reverse<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">False<\/span><span style=\"color: #D4D4D4\">)  <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u6309key\u6392\u5e8f\u4f7f\u7528\u4f8b\u5b50\uff1a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">list1.sort(<\/span><span style=\"color: #9CDCFE\">key<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\">:x[<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">list1_sorted = <\/span><span style=\"color: #DCDCAA\">sorted<\/span><span style=\"color: #D4D4D4\">(list1, <\/span><span style=\"color: #9CDCFE\">key<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\">:x[<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">])<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5bb9\u5668\u76f8\u5173<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"#\u5217\u8868\na = [123,&quot;abc&quot;] #\u53ef\u4ee5\u6709\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\ndp = [[0 for i in range(3)] for j in range(3)] #\u521b\u5efa\u4e8c\u7ef4\u5217\u8868[[0, 0, 0], [0, 0, 0], [0, 0, 0]]\nlist.append(x)\t#\u628a\u4e00\u4e2a\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u7684\u7ed3\u5c3e\nlist.index(x)\t#\u8fd4\u56de\u5217\u8868\u4e2d\u7b2c\u4e00\u4e2a\u503c\u4e3a x \u7684\u5143\u7d20\u7684\u7d22\u5f15\u3002\u5982\u679c\u6ca1\u6709\u5339\u914d\u7684\u5143\u7d20\u5c31\u4f1a\u8fd4\u56de\u4e00\u4e2a\u9519\u8bef\u3002\nlist.count(x)\t#\u8fd4\u56de x \u5728\u5217\u8868\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\u3002\nlist.sort()\t#\u5bf9\u5217\u8868\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\u3002\nlist.reverse()\t#\u5012\u6392\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002\nlist.pop() #\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5143\u7d20\u968f\u5373\u4ece\u5217\u8868\u4e2d\u88ab\u79fb\u9664\u3002\u53ef\u4ee5\u548cappend\u914d\u5408\u5b8c\u6210\u6808\u529f\u80fd\nlist.remove(x) #\u7528\u4e8e\u79fb\u9664\u5217\u8868\u4e2d\u67d0\u4e2a\u503c\u7684\u7b2c\u4e00\u4e2a\u5339\u914d\u9879\u3002x\u662f\u503c\uff0c\u4e0d\u662f\u7d22\u5f15\u3002\nlist.insert(index, obj) #\t\u5c06\u5bf9\u8c61\u63d2\u5165\u5217\u8868\u6307\u5b9a\u4f4d\u7f6e\uff0cindex = 0\u5c31\u662f\u63d2\u5165\u5728\u6700\u524d\u9762\nfor i, v in enumerate(['tic', 'tac', 'toe']): #\u6309\u7d22\u5f15\u904d\u5386\u5217\u8868\n  print(i, v)\n\n#\u96c6\u5408\n#\u521b\u5efa\nset1 = {1, 2, 3, 4}# \u76f4\u63a5\u4f7f\u7528\u5927\u62ec\u53f7\u521b\u5efa\u96c6\u5408\nset2 = set([4, 5, 6, 7])  # \u4f7f\u7528 set() \u51fd\u6570\u4ece\u5217\u8868\u521b\u5efa\u96c6\u5408\uff0c\u5373\u4ece\u5217\u8868\u8f6c\u6362\u4e3a\u96c6\u5408\nset3 = set() #\u6ce8\u610f\uff1a\u521b\u5efa\u4e00\u4e2a\u7a7a\u96c6\u5408\u5fc5\u987b\u7528 set() \u800c\u4e0d\u662f { }\uff0c\u56e0\u4e3a { } \u662f\u7528\u6765\u521b\u5efa\u4e00\u4e2a\u7a7a\u5b57\u5178\u3002\n#\u6dfb\u52a0\u5143\u7d20\nset1.add(5)\n#\u79fb\u9664\u5143\u7d20\uff0c\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728\u4f1a\u53d1\u751f\u9519\u8bef\ns.remove(x)\n#\u79fb\u9664\u5143\u7d20\uff0c\u4e0d\u5b58\u5728\u4e0d\u4f1a\u62a5\u9519\ns.discard(x) \n#set\u904d\u5386\u53ef\u4f7f\u7528\u7b80\u5355\u7684for in\nfor i in s:\n  print i\n\n#\u5b57\u5178\nknights = {'gallahad': 'the pure', 'robin': 'the brave'}\nfor k, v in knights.items(): #\u4f7f\u7528dict.items() \u6309\u952e\u503c\u904d\u5386\u5b57\u5178\n  print(k, v)\n  \n#deque\u53cc\u7aef\u961f\u5217\nfrom collections import deque\nqueue1 = deque([1, 2, 3])\nqueue1.append(4)  #\u53f3\u7aef\u5165\u961f\nqueue1.popleft() #\u5de6\u7aef\u5f39\u51fa\u5e76\u8fd4\u56de\u503c\uff0c\u6ca1\u6709\u5143\u7d20\u4f1a\u62a5\u9519\nqueue1.pop() #\u53f3\u7aef\u5f39\u51fa\u5e76\u8fd4\u56de\u503c\uff0c\u6ca1\u6709\u5143\u7d20\u4f1a\u62a5\u9519\n\n#\u5b57\u7b26\u4e32\n#\u6b63\u5411\u67e5\u627efind:\u8fd4\u56de\u8fd4\u56de\u5b57\u7b26\u4e32\u3010\u7b2c\u4e00\u6b21\u3011\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u6ca1\u6709\u5339\u914d\u9879\u5219\u8fd4\u56de-1\nstr.find(str, beg=0, end=len(string))\n#\u53cd\u5411\u67e5\u627erfind\uff1a\u8fd4\u56de\u8fd4\u56de\u5b57\u7b26\u4e32\u3010\u6700\u540e\u4e00\u6b21\u3011\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u6ca1\u6709\u5339\u914d\u9879\u5219\u8fd4\u56de-1\nstr.rfind(str, beg=0, end=len(string))\n\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">#\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">a = [<\/span><span style=\"color: #B5CEA8\">123<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;abc&quot;<\/span><span style=\"color: #D4D4D4\">] <\/span><span style=\"color: #6A9955\">#\u53ef\u4ee5\u6709\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">dp = [[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">)] <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> j <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">range<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">)] <\/span><span style=\"color: #6A9955\">#\u521b\u5efa\u4e8c\u7ef4\u5217\u8868[[0, 0, 0], [0, 0, 0], [0, 0, 0]]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.append(x)\t<\/span><span style=\"color: #6A9955\">#\u628a\u4e00\u4e2a\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u7684\u7ed3\u5c3e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.index(x)\t<\/span><span style=\"color: #6A9955\">#\u8fd4\u56de\u5217\u8868\u4e2d\u7b2c\u4e00\u4e2a\u503c\u4e3a x \u7684\u5143\u7d20\u7684\u7d22\u5f15\u3002\u5982\u679c\u6ca1\u6709\u5339\u914d\u7684\u5143\u7d20\u5c31\u4f1a\u8fd4\u56de\u4e00\u4e2a\u9519\u8bef\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.count(x)\t<\/span><span style=\"color: #6A9955\">#\u8fd4\u56de x \u5728\u5217\u8868\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.sort()\t<\/span><span style=\"color: #6A9955\">#\u5bf9\u5217\u8868\u4e2d\u7684\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.reverse()\t<\/span><span style=\"color: #6A9955\">#\u5012\u6392\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.pop() <\/span><span style=\"color: #6A9955\">#\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002\u5143\u7d20\u968f\u5373\u4ece\u5217\u8868\u4e2d\u88ab\u79fb\u9664\u3002\u53ef\u4ee5\u548cappend\u914d\u5408\u5b8c\u6210\u6808\u529f\u80fd<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.remove(x) <\/span><span style=\"color: #6A9955\">#\u7528\u4e8e\u79fb\u9664\u5217\u8868\u4e2d\u67d0\u4e2a\u503c\u7684\u7b2c\u4e00\u4e2a\u5339\u914d\u9879\u3002x\u662f\u503c\uff0c\u4e0d\u662f\u7d22\u5f15\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">.insert(index, obj) <\/span><span style=\"color: #6A9955\">#\t\u5c06\u5bf9\u8c61\u63d2\u5165\u5217\u8868\u6307\u5b9a\u4f4d\u7f6e\uff0cindex = 0\u5c31\u662f\u63d2\u5165\u5728\u6700\u524d\u9762<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i, v <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">enumerate<\/span><span style=\"color: #D4D4D4\">([<\/span><span style=\"color: #CE9178\">&#39;tic&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;tac&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;toe&#39;<\/span><span style=\"color: #D4D4D4\">]): <\/span><span style=\"color: #6A9955\">#\u6309\u7d22\u5f15\u904d\u5386\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(i, v)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u96c6\u5408<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u521b\u5efa<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">set1 = {<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">4<\/span><span style=\"color: #D4D4D4\">}<\/span><span style=\"color: #6A9955\"># \u76f4\u63a5\u4f7f\u7528\u5927\u62ec\u53f7\u521b\u5efa\u96c6\u5408<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">set2 = <\/span><span style=\"color: #4EC9B0\">set<\/span><span style=\"color: #D4D4D4\">([<\/span><span style=\"color: #B5CEA8\">4<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">6<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">7<\/span><span style=\"color: #D4D4D4\">])  <\/span><span style=\"color: #6A9955\"># \u4f7f\u7528 set() \u51fd\u6570\u4ece\u5217\u8868\u521b\u5efa\u96c6\u5408\uff0c\u5373\u4ece\u5217\u8868\u8f6c\u6362\u4e3a\u96c6\u5408<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">set3 = <\/span><span style=\"color: #4EC9B0\">set<\/span><span style=\"color: #D4D4D4\">() <\/span><span style=\"color: #6A9955\">#\u6ce8\u610f\uff1a\u521b\u5efa\u4e00\u4e2a\u7a7a\u96c6\u5408\u5fc5\u987b\u7528 set() \u800c\u4e0d\u662f { }\uff0c\u56e0\u4e3a { } \u662f\u7528\u6765\u521b\u5efa\u4e00\u4e2a\u7a7a\u5b57\u5178\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u6dfb\u52a0\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">set1.add(<\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u79fb\u9664\u5143\u7d20\uff0c\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728\u4f1a\u53d1\u751f\u9519\u8bef<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">s.remove(x)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u79fb\u9664\u5143\u7d20\uff0c\u4e0d\u5b58\u5728\u4e0d\u4f1a\u62a5\u9519<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">s.discard(x) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#set\u904d\u5386\u53ef\u4f7f\u7528\u7b80\u5355\u7684for in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> s:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\"> i<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u5b57\u5178<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">knights = {<\/span><span style=\"color: #CE9178\">&#39;gallahad&#39;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&#39;the pure&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;robin&#39;<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&#39;the brave&#39;<\/span><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> k, v <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> knights.items(): <\/span><span style=\"color: #6A9955\">#\u4f7f\u7528dict.items() \u6309\u952e\u503c\u904d\u5386\u5b57\u5178<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(k, v)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#deque\u53cc\u7aef\u961f\u5217<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">from<\/span><span style=\"color: #D4D4D4\"> collections <\/span><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> deque<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">queue1 = deque([<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">queue1.append(<\/span><span style=\"color: #B5CEA8\">4<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\">#\u53f3\u7aef\u5165\u961f<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">queue1.popleft() <\/span><span style=\"color: #6A9955\">#\u5de6\u7aef\u5f39\u51fa\u5e76\u8fd4\u56de\u503c\uff0c\u6ca1\u6709\u5143\u7d20\u4f1a\u62a5\u9519<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">queue1.pop() <\/span><span style=\"color: #6A9955\">#\u53f3\u7aef\u5f39\u51fa\u5e76\u8fd4\u56de\u503c\uff0c\u6ca1\u6709\u5143\u7d20\u4f1a\u62a5\u9519<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u5b57\u7b26\u4e32<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u6b63\u5411\u67e5\u627efind:\u8fd4\u56de\u8fd4\u56de\u5b57\u7b26\u4e32\u3010\u7b2c\u4e00\u6b21\u3011\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u6ca1\u6709\u5339\u914d\u9879\u5219\u8fd4\u56de-1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">str<\/span><span style=\"color: #D4D4D4\">.find(<\/span><span style=\"color: #4EC9B0\">str<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">beg<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">end<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #DCDCAA\">len<\/span><span style=\"color: #D4D4D4\">(string))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u53cd\u5411\u67e5\u627erfind\uff1a\u8fd4\u56de\u8fd4\u56de\u5b57\u7b26\u4e32\u3010\u6700\u540e\u4e00\u6b21\u3011\u51fa\u73b0\u7684\u4f4d\u7f6e\uff0c\u5982\u679c\u6ca1\u6709\u5339\u914d\u9879\u5219\u8fd4\u56de-1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #4EC9B0\">str<\/span><span style=\"color: #D4D4D4\">.rfind(<\/span><span style=\"color: #4EC9B0\">str<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">beg<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">end<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #DCDCAA\">len<\/span><span style=\"color: #D4D4D4\">(string))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f02\u5e38\u5904\u7406<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"try:\n  # \u53ef\u80fd\u51fa\u9519\u7684\u4ee3\u7801\nexcept(Exception1, Exception2, ... ) as e:\n  # \u53d1\u751f\u5f02\u5e38\u65f6\u6267\u884c\nelse:\n  # \u6b63\u786e\u65f6\u6267\u884c\nfinally:\n  # \u65e0\u8bba\u5bf9\u9519\u90fd\u6267\u884c\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">try<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># \u53ef\u80fd\u51fa\u9519\u7684\u4ee3\u7801<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">except<\/span><span style=\"color: #D4D4D4\">(Exception1, Exception2, ... ) <\/span><span style=\"color: #C586C0\">as<\/span><span style=\"color: #D4D4D4\"> e:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># \u53d1\u751f\u5f02\u5e38\u65f6\u6267\u884c<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># \u6b63\u786e\u65f6\u6267\u884c<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">finally<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># \u65e0\u8bba\u5bf9\u9519\u90fd\u6267\u884c<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\n# \u4e07\u80fd\u5f02\u5e38\u5904\u7406 try + except Exception as e\n\n# \u4f8b\u5b50\nfrom collections import deque\nqueue1 = deque()\ntry:\n    queue1.pop()\nexcept Exception as e:\n    print(e)           #pop from an empty deque\n    \n# \u5f53\u4e0d\u9700\u8981\u83b7\u53d6\u5f02\u5e38\u4fe1\u606f\u65f6\uff0c\u53ef\u4ee5\u4e0d\u52a0as\ntry:\n    value = int(input(&quot;\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570: &quot;))\nexcept ValueError:\n    print(&quot;\u8f93\u5165\u65e0\u6548\uff0c\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570&quot;)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4e07\u80fd\u5f02\u5e38\u5904\u7406 try + except Exception as e<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4f8b\u5b50<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">from<\/span><span style=\"color: #D4D4D4\"> collections <\/span><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> deque<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">queue1 = deque()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">try<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    queue1.pop()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">except<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Exception<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">as<\/span><span style=\"color: #D4D4D4\"> e:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(e)           <\/span><span style=\"color: #6A9955\">#pop from an empty deque<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5f53\u4e0d\u9700\u8981\u83b7\u53d6\u5f02\u5e38\u4fe1\u606f\u65f6\uff0c\u53ef\u4ee5\u4e0d\u52a0as<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">try<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    value = <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">input<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570: &quot;<\/span><span style=\"color: #D4D4D4\">))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">except<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">ValueError<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;\u8f93\u5165\u65e0\u6548\uff0c\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u9762\u5411\u5bf9\u8c61\u57fa\u7840<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"class Tree:\n   #\u7c7b\u53d8\u91cf\uff0c\u5373\u9759\u6001\u53d8\u91cf\uff0c\n   #\u8d4b\u503c\u65f6\uff0c\u9700\u8981\u901a\u8fc7Tree\u6765\u6253\u70b9\u8d4b\u503c\u624d\u80fd\u6b63\u786e\u4f7f\u7528\n   #\u82e5\u4f7f\u7528\u5b9e\u4f8btree\u6253\u70b9\u6765\u8d4b\u503c\uff0c\u5219tree\u5bf9\u8c61\u81ea\u5df1\u751f\u6210\u4e86\u4e00\u4e2a\u53d8\u91cfcount\u5e76\u8d4b\u503c\uff0c\u5e76\u6ca1\u6709\u66f4\u6539\u7c7b\u7684\u9759\u6001\u53d8\u91cf\u3002\n   #\u4f46\u8bbf\u95ee\u65f6\uff0c\u4f7f\u7528\u7c7b\u540d\u548c\u5b9e\u4f8b\u5747\u53ef\n   treeCount = 0 \n \n   def __init__(self, val, left, right): #\u6784\u9020\u51fd\u6570\n      self.val = val\n      self.left = left\n      self.right = right\n      Tree.treeCount += 1\n   \n   #\u5b9a\u4e49\u6210\u5458\u51fd\u6570\u65f6\u522b\u5fd8\u4e86\u52a0\u4e00\u4e2aself\u53c2\u6570\u3002\u5982\u679c\u4e0d\u52a0\uff0c\u4e00\u822c\u7528\u88c5\u9970\u5668@staticmethod\u4fee\u9970\uff0c\u53d8\u4e3a\u9759\u6001\u51fd\u6570\n   def displayCount(self): \n     print (&quot;Total Tree %d&quot; % Tree.treeCount)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #569CD6\">class<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4EC9B0\">Tree<\/span><span style=\"color: #D4D4D4\">:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\">#\u7c7b\u53d8\u91cf\uff0c\u5373\u9759\u6001\u53d8\u91cf\uff0c<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\">#\u8d4b\u503c\u65f6\uff0c\u9700\u8981\u901a\u8fc7Tree\u6765\u6253\u70b9\u8d4b\u503c\u624d\u80fd\u6b63\u786e\u4f7f\u7528<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\">#\u82e5\u4f7f\u7528\u5b9e\u4f8btree\u6253\u70b9\u6765\u8d4b\u503c\uff0c\u5219tree\u5bf9\u8c61\u81ea\u5df1\u751f\u6210\u4e86\u4e00\u4e2a\u53d8\u91cfcount\u5e76\u8d4b\u503c\uff0c\u5e76\u6ca1\u6709\u66f4\u6539\u7c7b\u7684\u9759\u6001\u53d8\u91cf\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\">#\u4f46\u8bbf\u95ee\u65f6\uff0c\u4f7f\u7528\u7c7b\u540d\u548c\u5b9e\u4f8b\u5747\u53ef<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   treeCount = <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">__init__<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">self<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">val<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">left<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">right<\/span><span style=\"color: #D4D4D4\">): <\/span><span style=\"color: #6A9955\">#\u6784\u9020\u51fd\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">      <\/span><span style=\"color: #569CD6\">self<\/span><span style=\"color: #D4D4D4\">.val = val<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">      <\/span><span style=\"color: #569CD6\">self<\/span><span style=\"color: #D4D4D4\">.left = left<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">      <\/span><span style=\"color: #569CD6\">self<\/span><span style=\"color: #D4D4D4\">.right = right<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">      Tree.treeCount += <\/span><span style=\"color: #B5CEA8\">1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\">#\u5b9a\u4e49\u6210\u5458\u51fd\u6570\u65f6\u522b\u5fd8\u4e86\u52a0\u4e00\u4e2aself\u53c2\u6570\u3002\u5982\u679c\u4e0d\u52a0\uff0c\u4e00\u822c\u7528\u88c5\u9970\u5668@staticmethod\u4fee\u9970\uff0c\u53d8\u4e3a\u9759\u6001\u51fd\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">displayCount<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">self<\/span><span style=\"color: #D4D4D4\">): <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">     <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #CE9178\">&quot;Total Tree <\/span><span style=\"color: #569CD6\">%d<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\"> % Tree.treeCount)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u6570\u4f20\u9012\u4e0e\u6df1\u62f7\u8d1d<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"#\u53c2\u6570\u4f20\u9012\uff1a\u53ef\u53d8\u7c7b\u578b\u4e0e\u4e0d\u53ef\u53d8\u7c7b\u578b\n#1\u3001\u4e0d\u53ef\u53d8\u7c7b\u578b\uff1a\u503c\u4f20\u9012\uff0c\u5982\u6574\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u3002\n#2\u3001\u53ef\u53d8\u7c7b\u578b\uff1a\u5f15\u7528\u4f20\u9012\uff0c\u5982 \u5217\u8868\uff0c\u5b57\u5178\u3002\n\n\n#\u6d45\u62f7\u8d1d\uff0c\u53ea\u62f7\u8d1d\u7236\u5bf9\u8c61\uff0c\u4e0d\u4f1a\u62f7\u8d1d\u5bf9\u8c61\u7684\u5185\u90e8\u7684\u5b50\u5bf9\u8c61\u3002\nb = a.copy()\n#\u6df1\u62f7\u8d1d\uff0c\u5b8c\u5168\u62f7\u8d1d\u4e86\u7236\u5bf9\u8c61\u53ca\u5176\u5b50\u5bf9\u8c61\u3002\nimport copy\nc = copy.deepcopy(a)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">#\u53c2\u6570\u4f20\u9012\uff1a\u53ef\u53d8\u7c7b\u578b\u4e0e\u4e0d\u53ef\u53d8\u7c7b\u578b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#1\u3001\u4e0d\u53ef\u53d8\u7c7b\u578b\uff1a\u503c\u4f20\u9012\uff0c\u5982\u6574\u6570\u3001\u5b57\u7b26\u4e32\u3001\u5143\u7ec4\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#2\u3001\u53ef\u53d8\u7c7b\u578b\uff1a\u5f15\u7528\u4f20\u9012\uff0c\u5982 \u5217\u8868\uff0c\u5b57\u5178\u3002<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u6d45\u62f7\u8d1d\uff0c\u53ea\u62f7\u8d1d\u7236\u5bf9\u8c61\uff0c\u4e0d\u4f1a\u62f7\u8d1d\u5bf9\u8c61\u7684\u5185\u90e8\u7684\u5b50\u5bf9\u8c61\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">b = a.copy()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u6df1\u62f7\u8d1d\uff0c\u5b8c\u5168\u62f7\u8d1d\u4e86\u7236\u5bf9\u8c61\u53ca\u5176\u5b50\u5bf9\u8c61\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> copy<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">c = copy.deepcopy(a)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"> \u4ee5\u4e0b\u4e3a\u516b\u80a1\uff08\u5ba2\u89c2\u9898\u7528\uff09<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">Python\u8bed\u8a00\u7c7b\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u662f<strong>\u5f3a\u7c7b\u578b<\/strong>\u7684\u52a8\u6001\u811a\u672c\u8bed\u8a00\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u5f3a\u7c7b\u578b\uff1a\u4e0d\u5141\u8bb8\u4e0d\u540c\u7c7b\u578b\u76f8\u52a0\u3002<br>\u52a8\u6001\uff1a\u4e0d\u4f7f\u7528\u663e\u793a\u6570\u636e\u7c7b\u578b\u58f0\u660e\uff0c\u4e14\u786e\u5b9a\u4e00\u4e2a\u53d8\u91cf\u7684\u7c7b\u578b\u662f\u5728\u7b2c\u4e00\u6b21\u7ed9\u5b83\u8d4b\u503c\u7684\u65f6\u5019\u3002<br>\u811a\u672c\u8bed\u8a00\uff1a\u4e00\u822c\u4e5f\u662f\u89e3\u91ca\u578b\u8bed\u8a00\uff0c\u8fd0\u884c\u4ee3\u7801\u53ea\u9700\u8981\u4e00\u4e2a\u89e3\u91ca\u5668\uff0c\u4e0d\u9700\u8981\u7f16\u8bd1\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f5c\u8005\uff1a\u7f16\u7a0b\u6587\u9752\u674e\u72d7\u86cb<br>\u94fe\u63a5\uff1a<a target=\"_blank\" href=\"https:\/\/www.nowcoder.com\/discuss\/378581336049594368\" rel=\"noreferrer noopener\">https:\/\/www.nowcoder.com\/discuss\/378581336049594368<\/a><br>\u6765\u6e90\uff1a\u725b\u5ba2\u7f51<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python\u4e2d\u5206\u4e3a\u516d\u79cd\u57fa\u672c\u6570\u636e\u7c7b\u578b<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u53d8\u7c7b\u578b\uff08\u53c8\u53eb\u52a8\u6001\u6570\u636e\u7c7b\u578b\uff0c\u652f\u6301\u589e\u5220\u6539\u64cd\u4f5c\uff09\uff1a\u5217\u8868(list)\u3001\u5b57\u5178(dictionary)\u3001\u96c6\u5408(set)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u53ef\u53d8\u7c7b\u578b\uff08\u53c8\u53eb\u9759\u6001\u6570\u636e\u7c7b\u578b\uff0c\u6ca1\u6709\u589e\u5220\u6539\u64cd\u4f5c\uff09\uff1a\u6570\u5b57(number)\u3001\u5b57\u7b26\u4e32(string)\u3001\u5143\u7ec4(tuple)<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6570\u5b57\u7c7b\u578b(Numbers)\uff1a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6570\u5b57\u7c7b\u578b\u4e0b\u8fd8\u53ef\u5206\u4e3a\u6574\u6570(int)\u3001\u6d6e\u70b9\u6570(float)\u3001\u590d\u6570(complex)\u3001\u5e03\u5c14(bool)<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"age = 22        # \u6574\u6570\u578b\uff0c\u53ef\u4ee5\u901a\u8fc7print(sys.maxsize)\u67e5\u770b\u6700\u5927\u53d6\u503c\u8303\u56f4\nprint(age)      # \u8f93\u51fa\uff1a22\n\nweight = 116.65 # \u6d6e\u70b9\u578b\nprint(weight)   # \u8f93\u51fa\uff1a116.65\n\nc1 = 1 + 2j\nc2 = 2 + 3j\nprint(c1+c2)    # \u8f93\u51fa\uff1a(3+5j)\uff0c\u590d\u6570\u5728\u5b9e\u9645\u5de5\u4f5c\u4e2d\u51e0\u4e4e\u7528\u4e0d\u5230\uff0c\u8bf7\u81ea\u884c\u4e86\u89e3\nprint(complex(2,1)) # \u8f93\u51fa\uff1a(2+1j)\n\n\nprint(True == 1)  # \u8f93\u51fa\uff1aTrue\nprint(False == 0) # \u8f93\u51fa\uff1aTrue\n# True==1\uff0cFalse==0 \uff0c\u56e0\u6b64True \u548c False \u53ef\u4ee5\u548c\u6570\u5b57\u76f8\u52a0\nprint(True + 1)   # \u8f93\u51fa\uff1a2\nprint(False - 2)  # \u8f93\u51fa\uff1a-2\n\n# \u2193\u5176\u5b9e\u5e03\u5c14\u578b\u5c31\u662f\u6574\u6570\u578b\u7684\u5b50\u7c7b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u51fd\u6570issubclass()\u5224\u65ad\uff0c\u8be5\u51fd\u6570\u662f\u7528\u4e8e\u5224\u65ad\u4e00\u4e2a\u7c7b\u578b\u5bf9\u8c61\u662f\u5426\u662f\u53e6\u4e00\u4e2a\u7c7b\u578b\u5bf9\u8c61\u7684\u5b50\u7c7b\nprint(issubclass(bool, int)) # \u8f93\u51fa\uff1aTrue\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">age = <\/span><span style=\"color: #B5CEA8\">22<\/span><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #6A9955\"># \u6574\u6570\u578b\uff0c\u53ef\u4ee5\u901a\u8fc7print(sys.maxsize)\u67e5\u770b\u6700\u5927\u53d6\u503c\u8303\u56f4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(age)      <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a22<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">weight = <\/span><span style=\"color: #B5CEA8\">116.65<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #6A9955\"># \u6d6e\u70b9\u578b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(weight)   <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a116.65<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">c1 = <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #569CD6\">j<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">c2 = <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #569CD6\">j<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(c1+c2)    <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a(3+5j)\uff0c\u590d\u6570\u5728\u5b9e\u9645\u5de5\u4f5c\u4e2d\u51e0\u4e4e\u7528\u4e0d\u5230\uff0c\u8bf7\u81ea\u884c\u4e86\u89e3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">complex<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">)) <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a(2+1j)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">True<\/span><span style=\"color: #D4D4D4\"> == <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1aTrue<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">False<\/span><span style=\"color: #D4D4D4\"> == <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1aTrue<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># True==1\uff0cFalse==0 \uff0c\u56e0\u6b64True \u548c False \u53ef\u4ee5\u548c\u6570\u5b57\u76f8\u52a0<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">True<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">)   <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">False<\/span><span style=\"color: #D4D4D4\"> - <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a-2<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u2193\u5176\u5b9e\u5e03\u5c14\u578b\u5c31\u662f\u6574\u6570\u578b\u7684\u5b50\u7c7b\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u51fd\u6570issubclass()\u5224\u65ad\uff0c\u8be5\u51fd\u6570\u662f\u7528\u4e8e\u5224\u65ad\u4e00\u4e2a\u7c7b\u578b\u5bf9\u8c61\u662f\u5426\u662f\u53e6\u4e00\u4e2a\u7c7b\u578b\u5bf9\u8c61\u7684\u5b50\u7c7b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">issubclass<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">bool<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #4EC9B0\">int<\/span><span style=\"color: #D4D4D4\">)) <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1aTrue<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5b57\u7b26\u4e32(String)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u7b26\u4e32\u5fc5\u987b\u4f7f\u7528<code>''<\/code>\u6216<code>\"\"<\/code>\u62ec\u8d77\u6765\uff0c\u5bf9\u4e8e\u7279\u6b8a\u5b57\u7b26\u53ef\u4ee5\u4f7f\u7528\u53cd\u659c\u6760<code>\\<\/code>\u8fdb\u884c<a href=\"https:\/\/so.csdn.net\/so\/search?q=%E8%BD%AC%E4%B9%89&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">\u8f6c\u4e49<\/a>\uff0c\u7528<code>+<\/code>\u62fc\u63a5\u591a\u4e2a\u5b57\u7b26\u4e32\uff0c \u7528<code>*<\/code>\u590d\u5236\u5b57\u7b26\u4e32\uff0c\u5b57\u7b26\u4e32\u8fd8\u652f\u6301\u7d22\u5f15\u622a\u53d6(\u53c8\u53eb\u5207\u7247)<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"name = &quot;ZhangSan&quot;   # \u5b57\u7b26\u4e32\u578b\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5355\u62ec\u53f7\nprint(name)         # \u8f93\u51fa\uff1aZhangSan\nprint(name * 2)    # \u8f93\u51fa\u5b57\u7b26\u4e32\u4e24\u6b21\uff0c\u4e5f\u53ef\u4ee5\u5199\u6210 print (2 * name)\uff0c\u8f93\u51fa\uff1aZhangSanZhangSan\nprint(name +'-123')# \u62fc\u63a5\u5b57\u7b26\u4e32\uff0c\u8f93\u51fa\uff1aZhangSan-123\nprint(name +'\\'123\\'')# \u62fc\u63a5\u5b57\u7b26\u4e32\u5e76\u5c06\u5355\u5f15\u53f7\u8f6c\u4e49\uff0c\u8f93\u51fa\uff1aZhangSan'123'\n\nprint(name[0:-1])  # \u8f93\u51fa\u7b2c\u4e00\u4e2a\u81f3\u5012\u6570\u7b2c\u4e8c\u4e2a\u7684\u5b57\u7b26\uff0c\u622a\u53d6\u65f6\u987e\u5934\u4e0d\u987e\u5c3e\uff0c\u8f93\u51fa\uff1aZhangSa\nprint(name[0])     # \u8f93\u51fa\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff0c\u8f93\u51fa\uff1aZ\nprint(name[-1])    # \u8f93\u51fa\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u8f93\u51fa\uff1an\nprint(name[2:])    # \u8f93\u51fa\u4ece\u7b2c\u4e09\u4e2a\u5f00\u59cb\u4e4b\u540e\u7684\u6240\u6709\u5b57\u7b26\uff0c\u8f93\u51fa\uff1aangSan\nprint(name[0:-1:2]) # \u8f93\u51fa\u7b2c\u4e00\u4e2a\u81f3\u5012\u6570\u7b2c\u4e8c\u4e2a\u7684\u5b57\u7b26\uff0c\u6b65\u957f\u4e3a2\uff0c\u8f93\u51fa\uff1aZaga\nprint(name[8])\t\t# \u82e5\u5b57\u7b26\u4e0d\u5b58\u5728\uff0c\u5219\u4f1a\u629b\u51faIndexError: string index out of range\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">name = <\/span><span style=\"color: #CE9178\">&quot;ZhangSan&quot;<\/span><span style=\"color: #D4D4D4\">   <\/span><span style=\"color: #6A9955\"># \u5b57\u7b26\u4e32\u578b\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5355\u62ec\u53f7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name)         <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1aZhangSan<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name * <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">)    <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\u5b57\u7b26\u4e32\u4e24\u6b21\uff0c\u4e5f\u53ef\u4ee5\u5199\u6210 print (2 * name)\uff0c\u8f93\u51fa\uff1aZhangSanZhangSan<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name +<\/span><span style=\"color: #CE9178\">&#39;-123&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><span style=\"color: #6A9955\"># \u62fc\u63a5\u5b57\u7b26\u4e32\uff0c\u8f93\u51fa\uff1aZhangSan-123<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name +<\/span><span style=\"color: #CE9178\">&#39;<\/span><span style=\"color: #D7BA7D\">\\&#39;<\/span><span style=\"color: #CE9178\">123<\/span><span style=\"color: #D7BA7D\">\\&#39;<\/span><span style=\"color: #CE9178\">&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><span style=\"color: #6A9955\"># \u62fc\u63a5\u5b57\u7b26\u4e32\u5e76\u5c06\u5355\u5f15\u53f7\u8f6c\u4e49\uff0c\u8f93\u51fa\uff1aZhangSan&#39;123&#39;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">:-<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">])  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\u7b2c\u4e00\u4e2a\u81f3\u5012\u6570\u7b2c\u4e8c\u4e2a\u7684\u5b57\u7b26\uff0c\u622a\u53d6\u65f6\u987e\u5934\u4e0d\u987e\u5c3e\uff0c\u8f93\u51fa\uff1aZhangSa<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">])     <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff0c\u8f93\u51fa\uff1aZ<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name[-<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">])    <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u8f93\u51fa\uff1an<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name[<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">:])    <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\u4ece\u7b2c\u4e09\u4e2a\u5f00\u59cb\u4e4b\u540e\u7684\u6240\u6709\u5b57\u7b26\uff0c\u8f93\u51fa\uff1aangSan<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">:-<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">:<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">]) <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\u7b2c\u4e00\u4e2a\u81f3\u5012\u6570\u7b2c\u4e8c\u4e2a\u7684\u5b57\u7b26\uff0c\u6b65\u957f\u4e3a2\uff0c\u8f93\u51fa\uff1aZaga<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(name[<\/span><span style=\"color: #B5CEA8\">8<\/span><span style=\"color: #D4D4D4\">])\t\t<\/span><span style=\"color: #6A9955\"># \u82e5\u5b57\u7b26\u4e0d\u5b58\u5728\uff0c\u5219\u4f1a\u629b\u51faIndexError: string index out of range<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5217\u8868(List)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5217\u8868\u662f\u4e00\u7ec4\u53ef\u91cd\u590d\u4e14\u6709\u5e8f\u7684\u6570\u636e\u96c6\u5408\uff0c\u4efb\u4f55\u7c7b\u578b\u7684\u6570\u636e\u90fd\u53ef\u4ee5\u5b58\u5230\u5217\u8868\u4e2d\uff0c\u4f1a\u6839\u636e\u9700\u8981\u52a8\u6001\u5206\u914d\u548c\u56de\u6536\u5185\u5b58\uff0c\u662fPython\u4e2d\u4f7f\u7528\u6700\u9891\u7e41\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5217\u8868\u540c\u6837\u4e5f\u652f\u6301\u7d22\u5f15\u622a\u53d6(\u53c8\u53eb\u5207\u7247)\uff0c\u5217\u8868\u4e2d\u7684\u5143\u7d20\u662f\u53ef\u53d8\u7684\uff0c\u80fd\u591f\u8fdb\u884c\u589e\u5220\u6539\u64cd\u4f5c<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u5217\u8868\u521b\u5efa\nl0 = []\t# \u521b\u5efa\u7a7a\u5217\u8868\nl1 = [&quot;\u5f20\u4e09&quot;,'lisi',12,[&quot;22&quot;,&quot;lisi&quot;,&quot;\u738b\u6b66&quot;],&quot;\u8d75\u67f3&quot;]  # \u76f4\u63a5\u4f7f\u7528\u4e2d\u62ec\u53f7\u521b\u5efa\u5217\u8868\nl2 = list(['lisi',12,(&quot;22&quot;,&quot;\u738b\u6b66&quot;),&quot;\u8d75\u67f3&quot;])  \t\t# \u6216\u8005\u8c03\u7528\u5185\u7f6e\u51fd\u6570list()\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u5217\u8868\u65f6\u4f7f\u7528\n\n# \u5217\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20\nl3 = [1,2]\nl4 = [&quot;\u58f9&quot;,&quot;er&quot;]\nl3.append(3)\t\t# \u5728l3\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u5143\u7d203\uff0c\u8f93\u51fa\uff1a[1, 2, 3]\nl3.append(l4)\t\t# \u5c06l4\u5217\u8868\u6dfb\u52a0\u5230l3\u5217\u8868\u672b\u5c3e\uff0c\u8f93\u51fa\uff1a[1, 2, ['\u58f9', 'er']]\nl3.extend(&quot;3L&quot;)\t\t# \u5728l3\u5217\u8868\u672b\u5c3e\u81f3\u5c11\u6dfb\u52a0\u4e24\u4e2a\u5143\u7d20\uff0c\u8f93\u51fa\uff1a[1, 2, '3', 'L']\nl3.extend(l4)\t\t# \u5c06l4\u5217\u8868\u6dfb\u52a0\u5230l3\u5217\u8868\u672b\u5c3e\uff0c\u7b49\u540c\u4e8el3+l4\uff0c\u8f93\u51fa\uff1a[1, 2, '\u58f9', 'er']\nl3.insert(1,&quot;\u5f20\u73ca&quot;)  # \u5728l3\u5217\u8868\u4e2d\u7d22\u5f15\u4e3a1\u7684\u4f4d\u7f6e\u63d2\u5165\u5143\u7d20\uff0c\u8f93\u51fa\uff1a[1, '\u5f20\u73ca', 2]\nl3.insert(0,l4)\t\t# \u5c06l4\u5217\u8868\u6dfb\u52a0\u5230l3\u5217\u8868\u5934\u90e8\uff0c\u8f93\u51fa\uff1a[['\u58f9', 'er'], 1, 2]\n\n\u6ce8\u610f\u4e09\u8005\u7684\u533a\u522b\uff1a\nappend()\uff1a\u6307\u5728\u5217\u8868\u7684\u672b\u5c3e\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u65b0\u5143\u7d20\u4f1a\u89c6\u4e3a\u4e00\u4e2a\u6574\u4f53\u8ffd\u52a0\u5230\u5217\u8868\u672b\u5c3e\nextend()\uff1a\u6307\u5728\u5217\u8868\u7684\u672b\u5c3e\u81f3\u5c11\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u65b0\u5143\u7d20\u4f1a\u5c06\u6574\u4f53\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e00\u4e2a\u4e00\u4e2a\u5730\u8ffd\u52a0\u5217\u8868\u672b\u5c3e\uff08\uff09 \u7c7b\u4f3c+\u53f7\ninsert()\uff1a\u6307\u5728\u5217\u8868\u7684\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u6dfb\u52a0\u5143\u7d20\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># \u5217\u8868\u521b\u5efa<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l0 = []\t<\/span><span style=\"color: #6A9955\"># \u521b\u5efa\u7a7a\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l1 = [<\/span><span style=\"color: #CE9178\">&quot;\u5f20\u4e09&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&#39;lisi&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">12<\/span><span style=\"color: #D4D4D4\">,[<\/span><span style=\"color: #CE9178\">&quot;22&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;lisi&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u738b\u6b66&quot;<\/span><span style=\"color: #D4D4D4\">],<\/span><span style=\"color: #CE9178\">&quot;\u8d75\u67f3&quot;<\/span><span style=\"color: #D4D4D4\">]  <\/span><span style=\"color: #6A9955\"># \u76f4\u63a5\u4f7f\u7528\u4e2d\u62ec\u53f7\u521b\u5efa\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l2 = <\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">([<\/span><span style=\"color: #CE9178\">&#39;lisi&#39;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">12<\/span><span style=\"color: #D4D4D4\">,(<\/span><span style=\"color: #CE9178\">&quot;22&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u738b\u6b66&quot;<\/span><span style=\"color: #D4D4D4\">),<\/span><span style=\"color: #CE9178\">&quot;\u8d75\u67f3&quot;<\/span><span style=\"color: #D4D4D4\">])  \t\t<\/span><span style=\"color: #6A9955\"># \u6216\u8005\u8c03\u7528\u5185\u7f6e\u51fd\u6570list()\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u5217\u8868\u65f6\u4f7f\u7528<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5217\u8868\u4e2d\u6dfb\u52a0\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l3 = [<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l4 = [<\/span><span style=\"color: #CE9178\">&quot;\u58f9&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;er&quot;<\/span><span style=\"color: #D4D4D4\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l3.append(<\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">)\t\t<\/span><span style=\"color: #6A9955\"># \u5728l3\u5217\u8868\u672b\u5c3e\u6dfb\u52a0\u5143\u7d203\uff0c\u8f93\u51fa\uff1a[1, 2, 3]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l3.append(l4)\t\t<\/span><span style=\"color: #6A9955\"># \u5c06l4\u5217\u8868\u6dfb\u52a0\u5230l3\u5217\u8868\u672b\u5c3e\uff0c\u8f93\u51fa\uff1a[1, 2, [&#39;\u58f9&#39;, &#39;er&#39;]]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l3.extend(<\/span><span style=\"color: #CE9178\">&quot;3L&quot;<\/span><span style=\"color: #D4D4D4\">)\t\t<\/span><span style=\"color: #6A9955\"># \u5728l3\u5217\u8868\u672b\u5c3e\u81f3\u5c11\u6dfb\u52a0\u4e24\u4e2a\u5143\u7d20\uff0c\u8f93\u51fa\uff1a[1, 2, &#39;3&#39;, &#39;L&#39;]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l3.extend(l4)\t\t<\/span><span style=\"color: #6A9955\"># \u5c06l4\u5217\u8868\u6dfb\u52a0\u5230l3\u5217\u8868\u672b\u5c3e\uff0c\u7b49\u540c\u4e8el3+l4\uff0c\u8f93\u51fa\uff1a[1, 2, &#39;\u58f9&#39;, &#39;er&#39;]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l3.insert(<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u5f20\u73ca&quot;<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># \u5728l3\u5217\u8868\u4e2d\u7d22\u5f15\u4e3a1\u7684\u4f4d\u7f6e\u63d2\u5165\u5143\u7d20\uff0c\u8f93\u51fa\uff1a[1, &#39;\u5f20\u73ca&#39;, 2]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">l3.insert(<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">,l4)\t\t<\/span><span style=\"color: #6A9955\"># \u5c06l4\u5217\u8868\u6dfb\u52a0\u5230l3\u5217\u8868\u5934\u90e8\uff0c\u8f93\u51fa\uff1a[[&#39;\u58f9&#39;, &#39;er&#39;], 1, 2]<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">\u6ce8\u610f\u4e09\u8005\u7684\u533a\u522b\uff1a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">append()\uff1a\u6307\u5728\u5217\u8868\u7684\u672b\u5c3e\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u65b0\u5143\u7d20\u4f1a\u89c6\u4e3a\u4e00\u4e2a\u6574\u4f53\u8ffd\u52a0\u5230\u5217\u8868\u672b\u5c3e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">extend()\uff1a\u6307\u5728\u5217\u8868\u7684\u672b\u5c3e\u81f3\u5c11\u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\uff0c\u65b0\u5143\u7d20\u4f1a\u5c06\u6574\u4f53\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4e00\u4e2a\u4e00\u4e2a\u5730\u8ffd\u52a0\u5217\u8868\u672b\u5c3e\uff08\uff09 \u7c7b\u4f3c+\u53f7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">insert()\uff1a\u6307\u5728\u5217\u8868\u7684\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u6dfb\u52a0\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5143\u7ec4(Tuple)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5143\u7ec4\u4e5f\u662f\u4e00\u7ec4\u53ef\u91cd\u590d\u4e14\u6709\u5e8f\u7684\u5bf9\u8c61\u96c6\u5408\uff0c\u4efb\u4f55\u7c7b\u578b\u7684\u6570\u636e\u90fd\u53ef\u4ee5\u5b58\u5230\u5143\u7ec4\u4e2d\uff0c\u4f46\u662f\u5143\u7ec4\u4e2d\u7684\u5143\u7d20\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u5143\u7ec4\u540c\u6837\u4e5f\u652f\u6301\u7d22\u5f15\u622a\u53d6(\u53c8\u53eb\u5207\u7247)<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u521b\u5efa\u5143\u7ec4\nt0 = ()\t\t# \u521b\u5efa\u7a7a\u5143\u7ec4\nt1 = (&quot;\u5f20\u73ca&quot;,&quot;lisi&quot;,[&quot;\u674e\u601d&quot;,12,&quot;Python&quot;],(&quot;\u738b\u6b66&quot;,&quot;22&quot;))\t# \u76f4\u63a5\u4f7f\u7528\u5c0f\u62ec\u53f7\u521b\u5efa\u5143\u7ec4\nt2 = (1,)\t\t\t\t\t\t# \u5f53\u5143\u7ec4\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u65f6\u9700\u8981\u5728\u540e\u9762\u52a0\u4e0a\u9017\u53f7\nt3 = tuple((&quot;\u4f9d\u513f&quot;,22,&quot;Java&quot;))   # \u6216\u8005\u8c03\u7528\u5185\u7f6e\u51fd\u6570tuple()\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u5143\u7ec4\u65f6\u4f7f\u7528\n\n# \u4fee\u6539\u5143\u7ec4\u4e2d\u7684\u53ef\u53d8\u5bf9\u8c61\nt1[2][1] = &quot;\u5341&quot;\t\t   # \u5c0612\u6539\u4e3a10\nt1[2].remove(&quot;Python&quot;)  # \u5220\u9664Python\u5143\u7d20\nt1[2].pop()\t\t\t\t# \u5220\u9664\u6700\u540e\u4e00\u4e2a\u5143\u7d20\nt1[2].clear()\t\t\t# \u6e05\u7a7a\u5217\u8868\nt1[2].append(&quot;\u554a\u54c8&quot;)\t   # \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20\n# \u62fc\u63a5\u5143\u7ec4\nprint(t2+t3)\t\t\t# \u8f93\u51fa\uff1a('1', '\u4f9d\u513f', 22, 'Java')\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># \u521b\u5efa\u5143\u7ec4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t0 = ()\t\t<\/span><span style=\"color: #6A9955\"># \u521b\u5efa\u7a7a\u5143\u7ec4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t1 = (<\/span><span style=\"color: #CE9178\">&quot;\u5f20\u73ca&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;lisi&quot;<\/span><span style=\"color: #D4D4D4\">,[<\/span><span style=\"color: #CE9178\">&quot;\u674e\u601d&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">12<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;Python&quot;<\/span><span style=\"color: #D4D4D4\">],(<\/span><span style=\"color: #CE9178\">&quot;\u738b\u6b66&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;22&quot;<\/span><span style=\"color: #D4D4D4\">))\t<\/span><span style=\"color: #6A9955\"># \u76f4\u63a5\u4f7f\u7528\u5c0f\u62ec\u53f7\u521b\u5efa\u5143\u7ec4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t2 = (<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">,)\t\t\t\t\t\t<\/span><span style=\"color: #6A9955\"># \u5f53\u5143\u7ec4\u53ea\u6709\u4e00\u4e2a\u5143\u7d20\u65f6\u9700\u8981\u5728\u540e\u9762\u52a0\u4e0a\u9017\u53f7<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t3 = <\/span><span style=\"color: #4EC9B0\">tuple<\/span><span style=\"color: #D4D4D4\">((<\/span><span style=\"color: #CE9178\">&quot;\u4f9d\u513f&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">22<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;Java&quot;<\/span><span style=\"color: #D4D4D4\">))   <\/span><span style=\"color: #6A9955\"># \u6216\u8005\u8c03\u7528\u5185\u7f6e\u51fd\u6570tuple()\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u5143\u7ec4\u65f6\u4f7f\u7528<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4fee\u6539\u5143\u7ec4\u4e2d\u7684\u53ef\u53d8\u5bf9\u8c61<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t1[<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">][<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">] = <\/span><span style=\"color: #CE9178\">&quot;\u5341&quot;<\/span><span style=\"color: #D4D4D4\">\t\t   <\/span><span style=\"color: #6A9955\"># \u5c0612\u6539\u4e3a10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t1[<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">].remove(<\/span><span style=\"color: #CE9178\">&quot;Python&quot;<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># \u5220\u9664Python\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t1[<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">].pop()\t\t\t\t<\/span><span style=\"color: #6A9955\"># \u5220\u9664\u6700\u540e\u4e00\u4e2a\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t1[<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">].clear()\t\t\t<\/span><span style=\"color: #6A9955\"># \u6e05\u7a7a\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">t1[<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">].append(<\/span><span style=\"color: #CE9178\">&quot;\u554a\u54c8&quot;<\/span><span style=\"color: #D4D4D4\">)\t   <\/span><span style=\"color: #6A9955\"># \u6dfb\u52a0\u4e00\u4e2a\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u62fc\u63a5\u5143\u7ec4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(t2+t3)\t\t\t<\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a(&#39;1&#39;, &#39;\u4f9d\u513f&#39;, 22, &#39;Java&#39;)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u5b57\u5178(Dictionary)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u5178\u662f\u4e00\u7ec4\u53ef\u53d8\u7684\u65e0\u5e8f\u7684\u5bf9\u8c61\u96c6\u5408\uff0c\u5b57\u5178\u4e2d\u7684\u5143\u7d20\u662f\u901a\u8fc7\u952e(Key) : \u503c(Value)\u6765\u4fdd\u5b58\u7684\uff0c\u4e00\u7ec4\u952e\u503c\u5bf9\u79f0\u4e3a\u4e00\u4e2a\u5143\u7d20\uff0c\u5176\u4e2d\u952e(Key)\u4e0d\u53ef\u91cd\u590d\uff0c\u5fc5\u987b\u552f\u4e00\uff0c\u800c\u503c(Value)\u662f\u53ef\u91cd\u590d\u7684\uff0c\u5b57\u5178\u4f1a\u6d6a\u8d39\u8f83\u5927\u5185\u5b58\uff0c\u662f\u4e00\u79cd\u4f7f\u7528\u7a7a\u95f4\u6362\u65f6\u95f4\u7684\u6570\u636e\u7c7b\u578b<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u521b\u5efa\u5b57\u5178\nd0 = {}\t\t# \u521b\u5efa\u7a7a\u5b57\u5178\nd1 = {&quot;\u5f20\u73ca&quot;:100,&quot;\u674e\u601d&quot;:120,&quot;\u738b\u6b66&quot;:110}\t# \u4f7f\u7528\u82b1\u62ec\u53f7\u521b\u5efa\u5b57\u5178\nd2 = dict(name=&quot;\u674e\u5c14&quot;,weight=116)\t\t   # \u8c03\u7528\u5185\u7f6e\u51fd\u6570dict()\u521b\u5efa\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u5b57\u5178\u65f6\u4f7f\u7528\n\n# \u83b7\u53d6\u5b57\u5178\u4e2d\u7684\u5143\u7d20\nprint(d1[&quot;\u674e\u601d&quot;])\t\t\t# \u4f7f\u7528\u4e2d\u62ec\u53f7\u6839\u636eKey\u83b7\u53d6Value\u503c\uff0c\u8f93\u51fa\uff1a120\nprint(d1[&quot;\u5f20\u4e09&quot;])\t\t\t# \u82e5Key\u4e0d\u5b58\u5728\uff0c\u5219\u629b\u51faKeyError: '\u5f20\u4e09'\n\n# \u2193\u8fd8\u53ef\u4ee5\u4f7f\u7528get()\u65b9\u6cd5\u53d6\u503c\uff0c\u6b64\u65b9\u5f0f\u82e5Key\u4e0d\u5b58\u5728\u5219\u8fd4\u56deNone\uff0c\u4e0d\u4f1a\u629b\u51faKeyError\u5f02\u5e38\uff0c\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u9ed8\u8ba4Value\nprint(d1.get(&quot;\u5f20\u73ca&quot;))\t\t# \u4f7f\u7528get()\u65b9\u6cd5\u53d6\u503c\uff0c\u8f93\u51fa\uff1a100\nprint(d1.get(&quot;\u738b\u6b66&quot;,98))\t# \u82e5\u5bf9\u5e94Key\u4e0d\u5b58\u5728\u5219\u8f93\u51fa\u9ed8\u8ba4\u503c\uff0c\u5426\u5219\u8f93\u51fa\u5bf9\u5e94\u7684Value\u503c\uff0c\u6b64\u5904\u8f93\u51fa\uff1a110\n\n# \u2193\u4f7f\u7528keys()\u65b9\u6cd5\u83b7\u53d6\u6240\u6709Key\nprint(d1.keys())\t\t # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key\uff0c\u8f93\u51fa\uff1adict_keys(['\u5f20\u73ca', '\u674e\u601d', '\u738b\u6b66'])\nprint(list(d1.keys()))\t # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key\u5e76\u8f6c\u4e3a\u5217\u8868\uff0c\u8f93\u51fa\uff1a['\u5f20\u73ca', '\u674e\u601d', '\u738b\u6b66']\nprint(tuple(d1.keys()))\t # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key\u5e76\u8f6c\u4e3a\u5143\u7ec4\uff0c\u8f93\u51fa\uff1a('\u5f20\u73ca', '\u674e\u601d', '\u738b\u6b66')\n\n# \u2193\u4f7f\u7528values()\u65b9\u6cd5\u83b7\u53d6\u6240\u6709Value\u503c\nprint(d1.values())\t\t # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Value\u503c\uff0c\u8f93\u51fa\uff1adict_values([100, 120, 110])\nprint(list(d1.values())) # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Value\u503c\u5e76\u8f6c\u4e3a\u5217\u8868\uff0c\u8f93\u51fa\uff1a[100, 120, 110]\nprint(tuple(d1.values()))# \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Value\u503c\u5e76\u8f6c\u4e3a\u5143\u7ec4\uff0c\u8f93\u51fa\uff1a(100, 120, 110)\n\n# \u2193\u4f7f\u7528items()\u65b9\u6cd5\u83b7\u53d6\u6240\u6709\u7684\u952e\u503c\u5bf9\nprint(d1.items())\t\t # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key:Value\uff0c\u8f93\u51fa\uff1adict_items([('\u5f20\u73ca', 100), ('\u674e\u601d', 120), ('\u738b\u6b66', 110)])\nprint(list(d1.items()))\t # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key:Value\u5e76\u8f6c\u4e3a\u5217\u8868\uff0c\u8f93\u51fa\uff1a[('\u5f20\u73ca', 100), ('\u674e\u601d', 120), ('\u738b\u6b66', 110)]\nprint(tuple(d1.items())) # \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key:Value\u5e76\u8f6c\u4e3a\u5143\u7ec4\uff0c\u8f93\u51fa\uff1a(('\u5f20\u73ca', 100), ('\u674e\u601d', 120), ('\u738b\u6b66', 110))\n\nfor item in d1:\t\t\t # \u76f4\u63a5\u4f7f\u7528for\u5faa\u73af\u904d\u5386\uff0c\u904d\u5386\u5f97\u5230\u7684\u662fKey\n    print(item)\t\t\t # \u8fd4\u56de\u5b57\u5178\u4e2d\u6240\u6709\u7684Key\n\nfor k, v in knights.items(): # \u800c\u904d\u5386dict.items() \uff0c\u662f\u6309Key:Value\u904d\u5386\u5b57\u5178\n    print(k, v)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># \u521b\u5efa\u5b57\u5178<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">d0 = {}\t\t<\/span><span style=\"color: #6A9955\"># \u521b\u5efa\u7a7a\u5b57\u5178<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">d1 = {<\/span><span style=\"color: #CE9178\">&quot;\u5f20\u73ca&quot;<\/span><span style=\"color: #D4D4D4\">:<\/span><span style=\"color: #B5CEA8\">100<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u674e\u601d&quot;<\/span><span style=\"color: #D4D4D4\">:<\/span><span style=\"color: #B5CEA8\">120<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u738b\u6b66&quot;<\/span><span style=\"color: #D4D4D4\">:<\/span><span style=\"color: #B5CEA8\">110<\/span><span style=\"color: #D4D4D4\">}\t<\/span><span style=\"color: #6A9955\"># \u4f7f\u7528\u82b1\u62ec\u53f7\u521b\u5efa\u5b57\u5178<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">d2 = <\/span><span style=\"color: #4EC9B0\">dict<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">name<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&quot;\u674e\u5c14&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #9CDCFE\">weight<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #B5CEA8\">116<\/span><span style=\"color: #D4D4D4\">)\t\t   <\/span><span style=\"color: #6A9955\"># \u8c03\u7528\u5185\u7f6e\u51fd\u6570dict()\u521b\u5efa\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u5b57\u5178\u65f6\u4f7f\u7528<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u7684\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(d1[<\/span><span style=\"color: #CE9178\">&quot;\u674e\u601d&quot;<\/span><span style=\"color: #D4D4D4\">])\t\t\t<\/span><span style=\"color: #6A9955\"># \u4f7f\u7528\u4e2d\u62ec\u53f7\u6839\u636eKey\u83b7\u53d6Value\u503c\uff0c\u8f93\u51fa\uff1a120<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(d1[<\/span><span style=\"color: #CE9178\">&quot;\u5f20\u4e09&quot;<\/span><span style=\"color: #D4D4D4\">])\t\t\t<\/span><span style=\"color: #6A9955\"># \u82e5Key\u4e0d\u5b58\u5728\uff0c\u5219\u629b\u51faKeyError: &#39;\u5f20\u4e09&#39;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u2193\u8fd8\u53ef\u4ee5\u4f7f\u7528get()\u65b9\u6cd5\u53d6\u503c\uff0c\u6b64\u65b9\u5f0f\u82e5Key\u4e0d\u5b58\u5728\u5219\u8fd4\u56deNone\uff0c\u4e0d\u4f1a\u629b\u51faKeyError\u5f02\u5e38\uff0c\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u9ed8\u8ba4Value<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(d1.get(<\/span><span style=\"color: #CE9178\">&quot;\u5f20\u73ca&quot;<\/span><span style=\"color: #D4D4D4\">))\t\t<\/span><span style=\"color: #6A9955\"># \u4f7f\u7528get()\u65b9\u6cd5\u53d6\u503c\uff0c\u8f93\u51fa\uff1a100<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(d1.get(<\/span><span style=\"color: #CE9178\">&quot;\u738b\u6b66&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #B5CEA8\">98<\/span><span style=\"color: #D4D4D4\">))\t<\/span><span style=\"color: #6A9955\"># \u82e5\u5bf9\u5e94Key\u4e0d\u5b58\u5728\u5219\u8f93\u51fa\u9ed8\u8ba4\u503c\uff0c\u5426\u5219\u8f93\u51fa\u5bf9\u5e94\u7684Value\u503c\uff0c\u6b64\u5904\u8f93\u51fa\uff1a110<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u2193\u4f7f\u7528keys()\u65b9\u6cd5\u83b7\u53d6\u6240\u6709Key<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(d1.keys())\t\t <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key\uff0c\u8f93\u51fa\uff1adict_keys([&#39;\u5f20\u73ca&#39;, &#39;\u674e\u601d&#39;, &#39;\u738b\u6b66&#39;])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(d1.keys()))\t <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key\u5e76\u8f6c\u4e3a\u5217\u8868\uff0c\u8f93\u51fa\uff1a[&#39;\u5f20\u73ca&#39;, &#39;\u674e\u601d&#39;, &#39;\u738b\u6b66&#39;]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">tuple<\/span><span style=\"color: #D4D4D4\">(d1.keys()))\t <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key\u5e76\u8f6c\u4e3a\u5143\u7ec4\uff0c\u8f93\u51fa\uff1a(&#39;\u5f20\u73ca&#39;, &#39;\u674e\u601d&#39;, &#39;\u738b\u6b66&#39;)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u2193\u4f7f\u7528values()\u65b9\u6cd5\u83b7\u53d6\u6240\u6709Value\u503c<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(d1.values())\t\t <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Value\u503c\uff0c\u8f93\u51fa\uff1adict_values([100, 120, 110])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(d1.values())) <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Value\u503c\u5e76\u8f6c\u4e3a\u5217\u8868\uff0c\u8f93\u51fa\uff1a[100, 120, 110]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">tuple<\/span><span style=\"color: #D4D4D4\">(d1.values()))<\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Value\u503c\u5e76\u8f6c\u4e3a\u5143\u7ec4\uff0c\u8f93\u51fa\uff1a(100, 120, 110)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u2193\u4f7f\u7528items()\u65b9\u6cd5\u83b7\u53d6\u6240\u6709\u7684\u952e\u503c\u5bf9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(d1.items())\t\t <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key:Value\uff0c\u8f93\u51fa\uff1adict_items([(&#39;\u5f20\u73ca&#39;, 100), (&#39;\u674e\u601d&#39;, 120), (&#39;\u738b\u6b66&#39;, 110)])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(d1.items()))\t <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key:Value\u5e76\u8f6c\u4e3a\u5217\u8868\uff0c\u8f93\u51fa\uff1a[(&#39;\u5f20\u73ca&#39;, 100), (&#39;\u674e\u601d&#39;, 120), (&#39;\u738b\u6b66&#39;, 110)]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #4EC9B0\">tuple<\/span><span style=\"color: #D4D4D4\">(d1.items())) <\/span><span style=\"color: #6A9955\"># \u83b7\u53d6\u5b57\u5178\u4e2d\u6240\u6709\u7684Key:Value\u5e76\u8f6c\u4e3a\u5143\u7ec4\uff0c\u8f93\u51fa\uff1a((&#39;\u5f20\u73ca&#39;, 100), (&#39;\u674e\u601d&#39;, 120), (&#39;\u738b\u6b66&#39;, 110))<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> item <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> d1:\t\t\t <\/span><span style=\"color: #6A9955\"># \u76f4\u63a5\u4f7f\u7528for\u5faa\u73af\u904d\u5386\uff0c\u904d\u5386\u5f97\u5230\u7684\u662fKey<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(item)\t\t\t <\/span><span style=\"color: #6A9955\"># \u8fd4\u56de\u5b57\u5178\u4e2d\u6240\u6709\u7684Key<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> k, v <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> knights.items(): <\/span><span style=\"color: #6A9955\"># \u800c\u904d\u5386dict.items() \uff0c\u662f\u6309Key:Value\u904d\u5386\u5b57\u5178<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(k, v)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u96c6\u5408(set)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u96c6\u5408\u662f\u4e00\u7ec4\u53ef\u53d8\u7684\u3001\u65e0\u5e8f\u7684\u4e14\u4e0d\u53ef\u91cd\u590d\u7684\u5143\u7d20\u5e8f\u5217<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u521b\u5efa\u96c6\u5408\ns0 = set()\t\t\t\t\t\t # \u521b\u5efa\u7a7a\u96c6\u5408\uff0c\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528\u82b1\u62ec\u53f7\uff0c\u82b1\u62ec\u53f7\u9ed8\u8ba4\u662f\u521b\u5efa\u5b57\u5178\ns1 = {&quot;\u674e\u601d&quot;,&quot;\u5f20\u73ca&quot;,&quot;\u674e\u601d&quot;,&quot;\u738b\u6b66&quot;}\t# \u82b1\u62ec\u53f7\u4e2d\u5143\u7d20\u975e\u952e\u503c\u5bf9\u65f6\uff0c\u521b\u5efa\u7684\u662f\u96c6\u5408\ns2 = set(&quot;\u674e\u5c14&quot;)\t\t\t\t\t# \u8c03\u7528\u5185\u90e8\u51fd\u6570set()\u521b\u5efa\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u96c6\u5408\u65f6\u4f7f\u7528\n#\u6dfb\u52a0\u5143\u7d20\nset1.add(5)\n#\u79fb\u9664\u5143\u7d20\uff0c\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728\u4f1a\u53d1\u751f\u9519\u8bef\ns.remove(x)\n#\u79fb\u9664\u5143\u7d20\uff0c\u4e0d\u5b58\u5728\u4e0d\u4f1a\u62a5\u9519\ns.discard(x) \n#set\u904d\u5386\u53ef\u4f7f\u7528\u7b80\u5355\u7684for in\nfor i in s:\n  print i\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># \u521b\u5efa\u96c6\u5408<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">s0 = <\/span><span style=\"color: #4EC9B0\">set<\/span><span style=\"color: #D4D4D4\">()\t\t\t\t\t\t <\/span><span style=\"color: #6A9955\"># \u521b\u5efa\u7a7a\u96c6\u5408\uff0c\u4e0d\u80fd\u76f4\u63a5\u4f7f\u7528\u82b1\u62ec\u53f7\uff0c\u82b1\u62ec\u53f7\u9ed8\u8ba4\u662f\u521b\u5efa\u5b57\u5178<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">s1 = {<\/span><span style=\"color: #CE9178\">&quot;\u674e\u601d&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u5f20\u73ca&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u674e\u601d&quot;<\/span><span style=\"color: #D4D4D4\">,<\/span><span style=\"color: #CE9178\">&quot;\u738b\u6b66&quot;<\/span><span style=\"color: #D4D4D4\">}\t<\/span><span style=\"color: #6A9955\"># \u82b1\u62ec\u53f7\u4e2d\u5143\u7d20\u975e\u952e\u503c\u5bf9\u65f6\uff0c\u521b\u5efa\u7684\u662f\u96c6\u5408<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">s2 = <\/span><span style=\"color: #4EC9B0\">set<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;\u674e\u5c14&quot;<\/span><span style=\"color: #D4D4D4\">)\t\t\t\t\t<\/span><span style=\"color: #6A9955\"># \u8c03\u7528\u5185\u90e8\u51fd\u6570set()\u521b\u5efa\uff0c\u901a\u5e38\u7528\u4e8e\u8f6c\u6362\u4e3a\u96c6\u5408\u65f6\u4f7f\u7528<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u6dfb\u52a0\u5143\u7d20<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">set1.add(<\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u79fb\u9664\u5143\u7d20\uff0c\u5982\u679c\u5143\u7d20\u4e0d\u5b58\u5728\u4f1a\u53d1\u751f\u9519\u8bef<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">s.remove(x)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#\u79fb\u9664\u5143\u7d20\uff0c\u4e0d\u5b58\u5728\u4e0d\u4f1a\u62a5\u9519<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">s.discard(x) <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">#set\u904d\u5386\u53ef\u4f7f\u7528\u7b80\u5355\u7684for in<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> s:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\"> i<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f4d\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&amp; \u6309\u4f4d\u4e0e<\/li>\n\n\n\n<li>| \u6309\u4f4d\u6216<\/li>\n\n\n\n<li>^ \u5f02\u6216<\/li>\n\n\n\n<li>~ \u6309\u4f4d\u53d6\u53cd<\/li>\n\n\n\n<li>&lt;&lt; \u5de6\u79fb<\/li>\n\n\n\n<li>&gt;&gt; \u53f3\u79fb<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"543\" data-original=\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-222\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u53d8\u91cf\u4f5c\u7528\u57df<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u53ef\u4ee5\u5206\u4e3a\u56db\u79cd\uff1a<strong>\u5c40\u90e8\u4f5c\u7528\u57df\u3001\u5d4c\u5957\u4f5c\u7528\u57df\u3001\u5168\u5c40\u4f5c\u7528\u57df\u548c\u5185\u7f6e\u4f5c\u7528\u57df<\/strong>\uff0c\u8fd9\u56db\u79cd\u4f5c\u7528\u57df\u9075\u5faa LEGB \u539f\u5219\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# 1. \u5c40\u90e8\u4f5c\u7528\u57df\uff08Local\uff09\n# \u5c40\u90e8\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\u662f\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\uff0c\u53ea\u80fd\u5728\u8be5\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u3002\ndef my_function():\n    x = 10  # \u5c40\u90e8\u53d8\u91cf\n    print(x)  # \u8f93\u51fa: 10\nmy_function()\nprint(x)  # \u62a5\u9519\uff0cx \u5728\u51fd\u6570\u5916\u90e8\u4e0d\u53ef\u8bbf\u95ee\n\n# 2. \u5d4c\u5957\u4f5c\u7528\u57df\uff08Enclosing\uff09\n# \u5d4c\u5957\u4f5c\u7528\u57df\u662f\u6307\u51fd\u6570\u5185\u90e8\u7684\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u5916\u5c42\u51fd\u6570\u7684\u53d8\u91cf\uff0c\u4f46\u65e0\u6cd5\u4fee\u6539\u5b83\uff08\u9664\u975e\u4f7f\u7528 nonlocal \u5173\u952e\u5b57\uff09\u3002\ndef outer_function():\n    x = 5  # \u5916\u5c42\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\n    def inner_function():\n        print(x)  # \u5185\u5c42\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u5916\u5c42\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\n    inner_function()\nouter_function()  # \u8f93\u51fa: 5\n\n# 3. \u5168\u5c40\u4f5c\u7528\u57df\uff08Global\uff09\n# \u5168\u5c40\u53d8\u91cf\u662f\u5728\u51fd\u6570\u4e4b\u5916\u5b9a\u4e49\u7684\uff0c\u53ef\u4ee5\u5728\u6574\u4e2a\u6a21\u5757\u4e2d\u8bbf\u95ee\u3002\u5982\u679c\u5728\u51fd\u6570\u5185\u90e8\u8981\u4fee\u6539\u5168\u5c40\u53d8\u91cf\uff0c\u5fc5\u987b\u4f7f\u7528 global \u5173\u952e\u5b57\u3002\nx = 20  # \u5168\u5c40\u53d8\u91cf\ndef my_function():\n    print(x)  # \u5728\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u5168\u5c40\u53d8\u91cf\nmy_function()  # \u8f93\u51fa: 20\n\n# 4. \u5185\u7f6e\u4f5c\u7528\u57df\uff08Built-in\uff09\n# \u5185\u7f6e\u4f5c\u7528\u57df\u5305\u542b Python \u89e3\u91ca\u5668\u5185\u7f6e\u7684\u53d8\u91cf\uff0c\u5982 len()\u3001range() \u7b49\u3002\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u8fd9\u4e9b\u5185\u7f6e\u7684\u51fd\u6570\u6216\u5e38\u91cf\u3002\nprint(len([1, 2, 3]))  # \u5185\u7f6e\u51fd\u6570 len()\uff0c\u8f93\u51fa: 3\n\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># 1. \u5c40\u90e8\u4f5c\u7528\u57df\uff08Local\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5c40\u90e8\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\u662f\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\uff0c\u53ea\u80fd\u5728\u8be5\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">my_function<\/span><span style=\"color: #D4D4D4\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    x = <\/span><span style=\"color: #B5CEA8\">10<\/span><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># \u5c40\u90e8\u53d8\u91cf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(x)  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa: 10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">my_function()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(x)  <\/span><span style=\"color: #6A9955\"># \u62a5\u9519\uff0cx \u5728\u51fd\u6570\u5916\u90e8\u4e0d\u53ef\u8bbf\u95ee<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># 2. \u5d4c\u5957\u4f5c\u7528\u57df\uff08Enclosing\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5d4c\u5957\u4f5c\u7528\u57df\u662f\u6307\u51fd\u6570\u5185\u90e8\u7684\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u5916\u5c42\u51fd\u6570\u7684\u53d8\u91cf\uff0c\u4f46\u65e0\u6cd5\u4fee\u6539\u5b83\uff08\u9664\u975e\u4f7f\u7528 nonlocal \u5173\u952e\u5b57\uff09\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">outer_function<\/span><span style=\"color: #D4D4D4\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    x = <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># \u5916\u5c42\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">inner_function<\/span><span style=\"color: #D4D4D4\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(x)  <\/span><span style=\"color: #6A9955\"># \u5185\u5c42\u51fd\u6570\u53ef\u4ee5\u8bbf\u95ee\u5916\u5c42\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    inner_function()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">outer_function()  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa: 5<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># 3. \u5168\u5c40\u4f5c\u7528\u57df\uff08Global\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5168\u5c40\u53d8\u91cf\u662f\u5728\u51fd\u6570\u4e4b\u5916\u5b9a\u4e49\u7684\uff0c\u53ef\u4ee5\u5728\u6574\u4e2a\u6a21\u5757\u4e2d\u8bbf\u95ee\u3002\u5982\u679c\u5728\u51fd\u6570\u5185\u90e8\u8981\u4fee\u6539\u5168\u5c40\u53d8\u91cf\uff0c\u5fc5\u987b\u4f7f\u7528 global \u5173\u952e\u5b57\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">x = <\/span><span style=\"color: #B5CEA8\">20<\/span><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #6A9955\"># \u5168\u5c40\u53d8\u91cf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">def<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">my_function<\/span><span style=\"color: #D4D4D4\">():<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(x)  <\/span><span style=\"color: #6A9955\"># \u5728\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u5168\u5c40\u53d8\u91cf<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">my_function()  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa: 20<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># 4. \u5185\u7f6e\u4f5c\u7528\u57df\uff08Built-in\uff09<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5185\u7f6e\u4f5c\u7528\u57df\u5305\u542b Python \u89e3\u91ca\u5668\u5185\u7f6e\u7684\u53d8\u91cf\uff0c\u5982 len()\u3001range() \u7b49\u3002\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u8bbf\u95ee\u8fd9\u4e9b\u5185\u7f6e\u7684\u51fd\u6570\u6216\u5e38\u91cf\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">len<\/span><span style=\"color: #D4D4D4\">([<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">]))  <\/span><span style=\"color: #6A9955\"># \u5185\u7f6e\u51fd\u6570 len()\uff0c\u8f93\u51fa: 3<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">LEGB \u89c4\u5219<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u53d8\u91cf\u4f5c\u7528\u57df\u7684\u67e5\u627e\u987a\u5e8f\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Local\uff08\u5c40\u90e8\u4f5c\u7528\u57df\uff09<\/strong>\uff1a\u5f53\u524d\u51fd\u6570\u5185\u5b9a\u4e49\u7684\u53d8\u91cf\u3002<\/li>\n\n\n\n<li><strong>Enclosing\uff08\u5d4c\u5957\u4f5c\u7528\u57df\uff09<\/strong>\uff1a\u5916\u90e8\u5d4c\u5957\u51fd\u6570\u7684\u53d8\u91cf\u3002<\/li>\n\n\n\n<li><strong>Global\uff08\u5168\u5c40\u4f5c\u7528\u57df\uff09<\/strong>\uff1a\u6a21\u5757\u9876\u7ea7\u5b9a\u4e49\u7684\u53d8\u91cf\uff08\u5373\u6574\u4e2a\u6587\u4ef6\uff09\u3002<\/li>\n\n\n\n<li><strong>Built-in\uff08\u5185\u7f6e\u4f5c\u7528\u57df\uff09<\/strong>\uff1aPython \u9884\u5b9a\u4e49\u7684\u53d8\u91cf\u548c\u51fd\u6570\uff0c\u5982 <code>len<\/code>\u3001<code>str<\/code>\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u627e\u53d8\u91cf\u65f6\uff0cPython \u4f1a\u6309\u7167\u8fd9\u4e2a\u987a\u5e8f\u9010\u5c42\u67e5\u627e\uff0c\u76f4\u5230\u627e\u5230\u53d8\u91cf\u3002\u5982\u679c\u672a\u627e\u5230\uff0c\u5219\u629b\u51fa <code>NameError<\/code>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6a21\u5757\u5bfc\u5165<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u5bfc\u5165\u65b9\u5f0f\n# import \n# import ... as ...\n# from ... import ...\n# from ... import *\n# \u4f7f\u7528\u524d\u4e24\u79cd\u65b9\u5f0f \u9700\u8981\u4f7f\u7528\u6a21\u5757\u540d.\u7c7b\u540d.\u65b9\u6cd5\n\n# \u4f8b\u5b50\uff1a\u5bfc\u5165datetime\u6a21\u5757\u91cc\u7684datetime\u7c7b\nfrom datetime import datetime\nprint(datetime.now())\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># \u5bfc\u5165\u65b9\u5f0f<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># import <\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># import ... as ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># from ... import ...<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># from ... import *<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4f7f\u7528\u524d\u4e24\u79cd\u65b9\u5f0f \u9700\u8981\u4f7f\u7528\u6a21\u5757\u540d.\u7c7b\u540d.\u65b9\u6cd5<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4f8b\u5b50\uff1a\u5bfc\u5165datetime\u6a21\u5757\u91cc\u7684datetime\u7c7b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">from<\/span><span style=\"color: #D4D4D4\"> datetime <\/span><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> datetime<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(datetime.now())<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b57\u5178\u952e\u503c<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python\u7684\u5b57\u5178\uff08dict\uff09\u5e95\u5c42\u57fa\u4e8e\u54c8\u5e0c\u8868\uff0c\u503c\u53ef\u4ee5\u53d6\u4efb\u4f55\u6570\u636e\u7c7b\u578b\uff0c\u4f46<strong>\u952e\u5fc5\u987b\u662f\u4e0d\u53ef\u53d8\u7684<\/strong>\uff0c\u5982\u5b57\u7b26\u4e32\u3001\u6570\u5b57\uff0c\u751a\u81f3\u5143\u7ec4\u4e5f\u53ef\u4ee5<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53ef\u53d8\u5bf9\u8c61\u4e0e\u4e0d\u53ef\u53d8\u5bf9\u8c61<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u53ef\u53d8\u5bf9\u8c61: bool\uff0cint\uff0cfloat\uff0ctuple\uff0cstr\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u53d8\u5bf9\u8c61: list\uff0cdict\uff0cset<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u51fd\u6570\u53ef\u53d8\u53c2\u6570\u4f20\u9012<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u6765\u5904\u7406\u53ef\u53d8\u53c2\u6570\uff0c\u63a5\u6536\u53c2\u6570\u540e\uff0cargs\u4f1a\u53d8\u6210\u4e00\u4e2atuple\uff0ckwargs\u4f1a\u53d8\u6210\u4e00\u4e2adict<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5143\u7ec4\u521d\u59cb\u5316<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u62ec\u53f7\u7684\u65b9\u5f0f\u521d\u59cb\u5316\u5355\u5143\u7d20\u5143\u7ec4\u65f6\uff0c\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a\u9017\u53f7\uff0c\u5426\u5219\u62ec\u53f7\u4f1a\u88ab\u8ba4\u4e3a\u662f\u8fd0\u7b97\u7b26\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"a=(1,) # \u6b63\u786e\na=(1) # \u9519\u8bef\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">a=(<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">,) <\/span><span style=\"color: #6A9955\"># \u6b63\u786e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">a=(<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #6A9955\"># \u9519\u8bef<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u5143\u8868\u8fbe\u5f0f<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">condition_is_true if condition else condition_is_false<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"condition_is_true if condition else condition_is_false\n# \u4f8b\u5b50\nmax = num if num&gt;max else max\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">condition_is_true <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> condition <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> condition_is_false<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4f8b\u5b50<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">max<\/span><span style=\"color: #D4D4D4\"> = num <\/span><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> num&gt;<\/span><span style=\"color: #DCDCAA\">max<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #C586C0\">else<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">max<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">lambda\uff08\u533f\u540d\u51fd\u6570\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Python \u4f7f\u7528&nbsp;<strong>lambda<\/strong>&nbsp;\u6765\u521b\u5efa\u533f\u540d\u51fd\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lambda \u51fd\u6570\u662f\u4e00\u79cd\u5c0f\u578b\u3001\u533f\u540d\u7684\u3001\u5185\u8054\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5177\u6709\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570\uff0c\u4f46\u53ea\u80fd\u6709\u4e00\u4e2a\u8868\u8fbe\u5f0f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u533f\u540d\u51fd\u6570\u4e0d\u9700\u8981\u4f7f\u7528&nbsp;<strong>def<\/strong>&nbsp;\u5173\u952e\u5b57\u5b9a\u4e49\u5b8c\u6574\u51fd\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lambda \u51fd\u6570\u901a\u5e38\u7528\u4e8e\u7f16\u5199\u7b80\u5355\u7684\u3001\u5355\u884c\u7684\u51fd\u6570\uff0c\u901a\u5e38\u5728\u9700\u8981\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\uff0c\u4f8b\u5982\u5728 map()\u3001filter()\u3001reduce() \u7b49\u51fd\u6570\u4e2d\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# \u65e0\u8f93\u5165\u53c2\u6570\nf = lambda: &quot;Hello, world!&quot;\nprint(f())  # \u8f93\u51fa: Hello, world!\n\n# \u6709\u8f93\u5165\u53c2\u6570\nx = lambda a : a + 10\nprint(x(5)) # \u8f93\u51fa\uff1a15\nx = lambda a, b : a * b\nprint(x(5, 6)) # \u8f93\u51fa\uff1a30\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># \u65e0\u8f93\u5165\u53c2\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">f = <\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\">: <\/span><span style=\"color: #CE9178\">&quot;Hello, world!&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(f())  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa: Hello, world!<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u6709\u8f93\u5165\u53c2\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">x = <\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">a<\/span><span style=\"color: #D4D4D4\"> : a + <\/span><span style=\"color: #B5CEA8\">10<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(x(<\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">)) <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a15<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">x = <\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">a<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">b<\/span><span style=\"color: #D4D4D4\"> : a * b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(x(<\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">6<\/span><span style=\"color: #D4D4D4\">)) <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa\uff1a30<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">lambda \u51fd\u6570\u901a\u5e38\u4e0e\u5185\u7f6e\u51fd\u6570\u5982 map()\u3001filter() \u548c reduce() \u4e00\u8d77\u4f7f\u7528\uff0c\u4ee5\u4fbf\u5728\u96c6\u5408\u4e0a\u6267\u884c\u64cd\u4f5c\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"numbers = [1, 2, 3, 4, 5]\nsquared = list(map(lambda x: x**2, numbers))\nprint(squared)  # \u8f93\u51fa: [1, 4, 9, 16, 25]\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">numbers = [<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">4<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">]<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">squared = <\/span><span style=\"color: #4EC9B0\">list<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #DCDCAA\">map<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #569CD6\">lambda<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">x<\/span><span style=\"color: #D4D4D4\">: x**<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">, numbers))<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(squared)  <\/span><span style=\"color: #6A9955\"># \u8f93\u51fa: [1, 4, 9, 16, 25]<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u5e38\u89c1\u6a21\u5757\u4f7f\u7528<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">sys\u6a21\u5757<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>sys.argv<\/strong>\uff1a\u53ef\u4ee5\u7528<code>sys.argv<\/code>\u83b7\u53d6\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u547d\u4ee4\u884c\u53c2\u6570\u7684\u53c2\u6570\u5217\u8868(list)\u3002\n<ul class=\"wp-block-list\">\n<li>sys.argv[0] \u5f53\u524d\u7a0b\u5e8f\u540d<\/li>\n\n\n\n<li>sys.argv[1] \u7b2c\u4e00\u4e2a\u53c2\u6570<\/li>\n\n\n\n<li>sys.argv[0] \u7b2c\u4e8c\u4e2a\u53c2\u6570<\/li>\n\n\n\n<li>&#8230;\u4ee5\u6b64\u7c7b\u63a8<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\u4ee3\u7801<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"# encoding: utf-8\n# filename: argv_test.py\nimport sys\n\n# \u83b7\u53d6\u811a\u672c\u540d\u5b57\nprint 'The name of this program is: %s' %(sys.argv[0])\n# \u83b7\u53d6\u53c2\u6570\u5217\u8868\nprint 'The command line arguments are:'\nfor i in sys.argv:\n    print i\n# \u7edf\u8ba1\u53c2\u6570\u4e2a\u6570\nprint 'There are %s arguments.'%(len(sys.argv)-1)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\"># encoding: utf-8<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># filename: argv_test.py<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> sys<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u83b7\u53d6\u811a\u672c\u540d\u5b57<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;The name of this program is: <\/span><span style=\"color: #569CD6\">%s<\/span><span style=\"color: #CE9178\">&#39;<\/span><span style=\"color: #D4D4D4\"> %(sys.argv[<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">])<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u83b7\u53d6\u53c2\u6570\u5217\u8868<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;The command line arguments are:&#39;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> i <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> sys.argv:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\"> i<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u7edf\u8ba1\u53c2\u6570\u4e2a\u6570<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;There are <\/span><span style=\"color: #569CD6\">%s<\/span><span style=\"color: #CE9178\"> arguments.&#39;<\/span><span style=\"color: #D4D4D4\">%(<\/span><span style=\"color: #DCDCAA\">len<\/span><span style=\"color: #D4D4D4\">(sys.argv)-<\/span><span style=\"color: #B5CEA8\">1<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\u7ed3\u679c<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"The name of this program is: argv_test.py\nThe command line arguments are:\nargv_test.py\narg1\narg2\narg3\nThere are 3 arguments.\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">The name of this program <\/span><span style=\"color: #C586C0\">is<\/span><span style=\"color: #D4D4D4\">: argv_test.py<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">The command line arguments are:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">argv_test.py<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">arg1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">arg2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">arg3<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">There are <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\"> arguments.<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>sys.platform<\/strong>\uff1a\u83b7\u53d6\u5f53\u524d\u6267\u884c\u73af\u5883\u7684\u5e73\u53f0\uff0c\u5982<code>win32<\/code>\u8868\u793a\u662fWindows 32bit\u64cd\u4f5c\u7cfb\u7edf\uff0c<code>linux2<\/code>\u8868\u793a\u662flinux\u5e73\u53f0\uff1b<\/li>\n\n\n\n<li><strong>sys.path<\/strong>\uff1apath\u662f\u4e00\u4e2a\u76ee\u5f55\u5217\u8868\uff0c\u4f9bPython\u4ece\u4e2d\u67e5\u627e\u7b2c\u4e09\u65b9\u6269\u5c55\u6a21\u5757\u3002\u5728python\u542f\u52a8\u65f6\uff0c<code>sys.path<\/code>\u6839\u636e\u5185\u5efa\u89c4\u5219\u3001PYTHONPATH\u53d8\u91cf\u8fdb\u884c\u521d\u59cb\u5316\u3002<\/li>\n\n\n\n<li><strong>sys.exit(n)<\/strong>\uff1a\u8c03\u7528<code>sys.exit(n)<\/code>\u53ef\u4ee5\u4e2d\u9014\u9000\u51fa\u7a0b\u5e8f\uff0c\u5f53\u53c2\u6570\u975e0\u65f6\uff0c\u4f1a\u5f15\u53d1\u4e00\u4e2a<code>SystemExit<\/code>\u5f02\u5e38\uff0c\u4ece\u800c\u53ef\u4ee5\u5728\u4e3b\u7a0b\u5e8f\u4e2d\u6355\u83b7\u8be5\u5f02\u5e38\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">os\u6a21\u5757<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">os \u6a21\u5757\u5e38\u7528\u65b9\u6cd5 \u76f8\u5e94\u7684\u4f5c\u7528<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>os.chdir(path) \u6539\u53d8\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\uff0cpath\u5fc5\u987b\u4e3a\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u76ee\u5f55<\/li>\n\n\n\n<li>os.getcwd() \u8fd4\u56de\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<\/li>\n\n\n\n<li>os.listdir(path) \u5217\u4e3e\u6307\u5b9a\u76ee\u5f55\u7684\u6587\u4ef6\u540d<\/li>\n\n\n\n<li>os.mkdir(path) \u521b\u5efapath\u6307\u5b9a\u7684\u6587\u4ef6\u5939,\u53ea\u80fd\u521b\u5efa\u4e00\u4e2a\u5355\u5c42\u6587\u4ef6\uff0c\u800c\u4e0d\u80fd\u5d4c\u5957\u521b\u5efa\uff0c\u82e5\u6587\u4ef6\u5939\u5b58\u5728\u5219\u4f1a\u629b\u51fa\u5f02\u5e38<\/li>\n\n\n\n<li>os.makedirs(path) \u521b\u5efa\u591a\u5c42\u76ee\u5f55 \uff0c\u53ef\u4ee5\u5d4c\u5957\u521b\u5efa<\/li>\n\n\n\n<li>os.move(file_name) \u5220\u9664\u6307\u5b9a\u6587\u4ef6<\/li>\n\n\n\n<li>os.rmdir(path) \u5220\u9664\u5355\u5c42\u76ee\u5f55\uff0c\u9047\u89c1\u76ee\u5f55\u975e\u7a7a\u65f6\u5219\u4f1a\u629b\u51fa\u5f02\u5e38<\/li>\n\n\n\n<li>os.removedirs(path) \u9010\u5c42\u5220\u9664\u591a\u5c42\u76ee\u5f55<\/li>\n\n\n\n<li>os.rename(old,new) \u6587\u4ef6old\u91cd\u547d\u540d\u4e3anew<\/li>\n\n\n\n<li>os.system(command) \u8fd0\u884c\u7cfb\u7edf\u7684\u547d\u4ee4\u7a97\u53e3<\/li>\n\n\n\n<li>os.walk(dir)\u4ee5\u9012\u5f52\u7684\u65b9\u5f0f\u904d\u5386\u6587\u4ef6\u5939\uff0c\u8fd4\u56de\u503c\u4e3a\u8fed\u4ee3\u5668\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u5bf9\u8c61\u4e3a\u4e00\u4e2a\u4e09\u5143\u7ec4(dirpath, dirnames, filenames)\uff0cdirpath\u4e3a\u76ee\u5f55\uff0cdirnames\u4e3a\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u7684\u5b50\u76ee\u5f55\u540d\uff0cfilenames\u4e3a\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6587\u4ef6\u540d<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">os.path \u6a21\u5757\u5e38\u7528\u65b9\u6cd5 \u76f8\u5e94\u7684\u4f5c\u7528<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>abspath(path) \u8fd4\u56de\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u7edd\u5bf9\u8def\u5f84<\/li>\n\n\n\n<li>basename(path) \u8fd4\u56depath\u8def\u5f84\u6700\u540e\u4e00\u4e2a\\\u540e\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u4e3a\u7a7a<\/li>\n\n\n\n<li>dirname(path) \u8fd4\u56depath\u8def\u5f84\u6700\u540e\u4e00\u4e2a\\\u4e4b\u524d\u7684\u5185\u5bb9<\/li>\n\n\n\n<li>split(path) \u8fd4\u56de\u4e00\u4e2a\uff08head,tail\uff09\u5143\u7ec4\uff0chead\u4e3a\u6700\u540e\\\u4e4b\u524d\u7684\u5185\u5bb9\uff1btail\u4e3a\u6700\u540e\\\u4e4b\u540e\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u4e3a\u7a7a<\/li>\n\n\n\n<li>splitext(path) \u8fd4\u56de\u6307\u5411\u6587\u4ef6\u7684\u8def\u5f84\u548c\u6269\u5c55\u540d<\/li>\n\n\n\n<li>exists(path) \u67e5\u8be2\u8def\u5f84path\u662f\u5426\u5b58\u5728<\/li>\n\n\n\n<li>isabs(s) \u5224\u65ad\u6307\u5b9a\u8def\u5f84s\u662f\u5426\u4e3a\u7edd\u5bf9\u8def\u5f84<\/li>\n\n\n\n<li>isdir(path) \u5224\u65adpath\u6307\u5411\u7684\u662f\u5426\u662f\u6587\u4ef6\u5939<\/li>\n\n\n\n<li>isfile(path) \u5224\u65adpath\u662f\u5426\u6307\u5411\u6587\u4ef6<\/li>\n\n\n\n<li>join(path,*path) \u5c06\u4e24\u4e2apath\u901a\u8fc7\\\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u6216\u5c06\u66f4\u591apath\u7ec4\u5408\u5728\u4e00\u8d77<\/li>\n\n\n\n<li>getatime(filename) \u8fd4\u56de\u6587\u4ef6\u7684\u6700\u8fd1\u8bbf\u95ee\u65f6\u95f4,\u8fd4\u56de\u7684\u662f\u6d6e\u70b9\u6570\u65f6\u95f4<\/li>\n\n\n\n<li>getctime(filename) \u8fd4\u56de\u6587\u4ef6\u7684\u521b\u5efa\u65f6\u95f4<\/li>\n\n\n\n<li>getmtime(filename) \u8fd4\u56de\u6587\u4ef6\u7684\u4fee\u6539\u65f6\u95f4<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">datetime\u6a21\u5757<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>datetime.now() \u8fd4\u56de\u5f53\u524d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import datetime\nnow = datetime.datetime.now()\nprint(now)  # \u5982\uff1a2024-10-14 10:45:23.123456\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> datetime<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">now = datetime.datetime.now()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(now)  <\/span><span style=\"color: #6A9955\"># \u5982\uff1a2024-10-14 10:45:23.123456<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>datetime.strptime() \u5c06\u5b57\u7b26\u4e32\u89e3\u6790\u4e3a datetime \u5bf9\u8c61\u3002\u9700\u8981\u6307\u5b9a\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import datetime\ndate_string = &quot;2024-10-14 10:45:23&quot;\ndate_object = datetime.datetime.strptime(date_string, &quot;%Y-%m-%d %H:%M:%S&quot;)\nprint(date_object)  # 2024-10-14 10:45:23\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> datetime<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">date_string = <\/span><span style=\"color: #CE9178\">&quot;2024-10-14 10:45:23&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">date_object = datetime.datetime.strptime(date_string, <\/span><span style=\"color: #CE9178\">&quot;%Y-%m-<\/span><span style=\"color: #569CD6\">%d<\/span><span style=\"color: #CE9178\"> %H:%M:%S&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(date_object)  <\/span><span style=\"color: #6A9955\"># 2024-10-14 10:45:23<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>datetime.strftime() \u5c06 datetime \u5bf9\u8c61\u683c\u5f0f\u5316\u4e3a\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import datetime\nnow = datetime.datetime.now()\ndate_string = now.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)\nprint(date_string)  # \u5982\uff1a2024-10-14 10:45:23\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> datetime<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">now = datetime.datetime.now()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">date_string = now.strftime(<\/span><span style=\"color: #CE9178\">&quot;%Y-%m-<\/span><span style=\"color: #569CD6\">%d<\/span><span style=\"color: #CE9178\"> %H:%M:%S&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(date_string)  <\/span><span style=\"color: #6A9955\"># \u5982\uff1a2024-10-14 10:45:23<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>datetime.timedelta() \u7528\u4e8e\u65f6\u95f4\u7684\u52a0\u51cf\u6cd5\u64cd\u4f5c\u3002\u53ef\u4ee5\u8868\u793a\u65f6\u95f4\u7684\u5dee\u503c\uff0c\u5982\u5929\u6570\u3001\u5c0f\u65f6\u3001\u5206\u949f\u7b49\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import datetime\nnow = datetime.datetime.now()\ndelta = datetime.timedelta(days=5)\nfuture = now + delta  # 5\u5929\u540e\nprint(future)  # \u5982\uff1a2024-10-19 10:45:23\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> datetime<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">now = datetime.datetime.now()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">delta = datetime.timedelta(<\/span><span style=\"color: #9CDCFE\">days<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">future = now + delta  <\/span><span style=\"color: #6A9955\"># 5\u5929\u540e<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(future)  <\/span><span style=\"color: #6A9955\"># \u5982\uff1a2024-10-19 10:45:23<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">time\u6a21\u5757<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>time.time() \u8fd4\u56de\u5f53\u524d\u65f6\u95f4\u7684\u65f6\u95f4\u6233\uff08\u4ece Unix \u7eaa\u5143\uff081970\u5e741\u67081\u65e5\uff09\u5f00\u59cb\u7684\u79d2\u6570\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import time\ntimestamp = time.time()\nprint(timestamp)  # \u5982\uff1a1697255179.123456\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">timestamp = time.time()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(timestamp)  <\/span><span style=\"color: #6A9955\"># \u5982\uff1a1697255179.123456<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>time.sleep() \u4f7f\u7a0b\u5e8f\u6682\u505c\u6267\u884c\u6307\u5b9a\u7684\u79d2\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import time\nprint(&quot;Start&quot;)\ntime.sleep(2)  # \u7a0b\u5e8f\u6682\u505c 2 \u79d2\nprint(&quot;End&quot;)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;Start&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">time.sleep(<\/span><span style=\"color: #B5CEA8\">2<\/span><span style=\"color: #D4D4D4\">)  <\/span><span style=\"color: #6A9955\"># \u7a0b\u5e8f\u6682\u505c 2 \u79d2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&quot;End&quot;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>time.localtime() \u5c06\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u7ed3\u6784\u5316\u7684\u672c\u5730\u65f6\u95f4\uff08struct_time \u5bf9\u8c61\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import time\nlocal_time = time.localtime()\nprint(local_time)  # \u5982\uff1atime.struct_time(tm_year=2024, tm_mon=10, tm_mday=14, ...)\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">local_time = time.localtime()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(local_time)  <\/span><span style=\"color: #6A9955\"># \u5982\uff1atime.struct_time(tm_year=2024, tm_mon=10, tm_mday=14, ...)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>time.strftime() \u6839\u636e\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5c06 struct_time \u6216\u65f6\u95f4\u6233\u8f6c\u6362\u4e3a\u53ef\u8bfb\u7684\u65f6\u95f4\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"import time\nformatted_time = time.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;, time.localtime())\nprint(formatted_time)  # \u5982\uff1a2024-10-14 10:45:23\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">import<\/span><span style=\"color: #D4D4D4\"> time<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">formatted_time = time.strftime(<\/span><span style=\"color: #CE9178\">&quot;%Y-%m-<\/span><span style=\"color: #569CD6\">%d<\/span><span style=\"color: #CE9178\"> %H:%M:%S&quot;<\/span><span style=\"color: #D4D4D4\">, time.localtime())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(formatted_time)  <\/span><span style=\"color: #6A9955\"># \u5982\uff1a2024-10-14 10:45:23<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">io\u548c\u8bfb\u5199\u6587\u4ef6<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">Python<\/span><span role=\"button\" tabindex=\"0\" data-code=\"f = open(filename, mode='r')\n# file: \u6587\u4ef6\u8def\u5f84\uff08\u5b57\u7b26\u4e32\uff09\u3002\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\u3002\n# mode: \u6587\u4ef6\u6253\u5f00\u6a21\u5f0f\uff0c\u51b3\u5b9a\u4e86\u6587\u4ef6\u5982\u4f55\u88ab\u5904\u7406\u3002\u5e38\u89c1\u6a21\u5f0f\u6709\uff1a\n'r': \u4ee5\u53ea\u8bfb\u6a21\u5f0f\u6253\u5f00\uff08\u9ed8\u8ba4\uff09\u3002\n'w': \u4ee5\u5199\u5165\u6a21\u5f0f\u6253\u5f00\uff0c\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\u4f1a\u521b\u5efa\u6587\u4ef6\uff1b\u5982\u679c\u6587\u4ef6\u5b58\u5728\u5219\u6e05\u7a7a\u6587\u4ef6\u3002\n'a': \u4ee5\u8ffd\u52a0\u6a21\u5f0f\u6253\u5f00\uff0c\u6570\u636e\u4f1a\u88ab\u5199\u5165\u5230\u6587\u4ef6\u672b\u5c3e\u3002\n'b': \u4ee5\u4e8c\u8fdb\u5236\u6a21\u5f0f\u6253\u5f00\uff08\u53ef\u4ee5\u4e0e\u5176\u4ed6\u6a21\u5f0f\u4e00\u8d77\u4f7f\u7528\uff0c\u5982 'rb'\u3001'wb'\uff09\u3002\n't': \u4ee5\u6587\u672c\u6a21\u5f0f\u6253\u5f00\uff08\u9ed8\u8ba4\uff0c\u4e0e\u5176\u4ed6\u6a21\u5f0f\u7ec4\u5408\u4f7f\u7528\uff0c\u5982 'rt'\uff09\u3002\n'x': \u4ee5\u72ec\u5360\u521b\u5efa\u6a21\u5f0f\u6253\u5f00\uff0c\u6587\u4ef6\u4e0d\u5b58\u5728\u5219\u521b\u5efa\uff0c\u5b58\u5728\u5219\u5f15\u53d1\u9519\u8bef\u3002\n'+': \u6253\u5f00\u6587\u4ef6\u8fdb\u884c\u66f4\u65b0\uff08\u8bfb\u548c\u5199\uff09\uff0c\u53ef\u4ee5\u4e0e\u5176\u4ed6\u6a21\u5f0f\u7ec4\u5408\u4f7f\u7528\uff0c\u5982 'r+'\u3001'w+' \u7b49\u3002\n\n# \u5e38\u89c1\u7528\u6cd5\n# \u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\nwith open('example.txt', 'r') as file:\n    content = file.read()\n    print(content)\n# \u5199\u5165\u6587\u4ef6\nwith open('example.txt', 'w') as file:\n    file.write('Hello, World!')\n# \u8ffd\u52a0\u5199\u5165\u6587\u4ef6\nwith open('example.txt', 'a') as file:\n    file.write('\\nAppending this line.')\n# \u9010\u884c\u8bfb\u53d6\u6587\u4ef6\nwith open('example.txt', 'r') as file:\n    for line in file:\n        print(line.strip())  # \u53bb\u9664\u6362\u884c\u7b26\n\n# \u4f7f\u7528 with open(...) as \u662f\u63a8\u8350\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5728 with \u5757\u7ed3\u675f\u65f6\u81ea\u52a8\u5173\u95ed\u6587\u4ef6\uff0c\u9632\u6b62\u8d44\u6e90\u6cc4\u6f0f\u3002\n# \u5982\u679c\u4e0d\u4f7f\u7528with open\uff0c\u76f4\u63a5f = open()\uff0c\u5219\u9700\u8981f.close()\u624b\u52a8\u5173\u95ed\n# \u6b64\u5916open()\u8fd8\u53ef\u4ee5\u52a0\u4e0a encoding='utf-8'\u53c2\u6570\uff0c\u4ee5\u9632\u6b62\u7f16\u7801\u95ee\u9898\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">f = <\/span><span style=\"color: #DCDCAA\">open<\/span><span style=\"color: #D4D4D4\">(filename, <\/span><span style=\"color: #9CDCFE\">mode<\/span><span style=\"color: #D4D4D4\">=<\/span><span style=\"color: #CE9178\">&#39;r&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># file: \u6587\u4ef6\u8def\u5f84\uff08\u5b57\u7b26\u4e32\uff09\u3002\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># mode: \u6587\u4ef6\u6253\u5f00\u6a21\u5f0f\uff0c\u51b3\u5b9a\u4e86\u6587\u4ef6\u5982\u4f55\u88ab\u5904\u7406\u3002\u5e38\u89c1\u6a21\u5f0f\u6709\uff1a<\/span><\/span>\n<span class=\"line\"><span style=\"color: #CE9178\">&#39;r&#39;<\/span><span style=\"color: #D4D4D4\">: \u4ee5\u53ea\u8bfb\u6a21\u5f0f\u6253\u5f00\uff08\u9ed8\u8ba4\uff09\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #CE9178\">&#39;w&#39;<\/span><span style=\"color: #D4D4D4\">: \u4ee5\u5199\u5165\u6a21\u5f0f\u6253\u5f00\uff0c\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\u4f1a\u521b\u5efa\u6587\u4ef6\uff1b\u5982\u679c\u6587\u4ef6\u5b58\u5728\u5219\u6e05\u7a7a\u6587\u4ef6\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #CE9178\">&#39;a&#39;<\/span><span style=\"color: #D4D4D4\">: \u4ee5\u8ffd\u52a0\u6a21\u5f0f\u6253\u5f00\uff0c\u6570\u636e\u4f1a\u88ab\u5199\u5165\u5230\u6587\u4ef6\u672b\u5c3e\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #CE9178\">&#39;b&#39;<\/span><span style=\"color: #D4D4D4\">: \u4ee5\u4e8c\u8fdb\u5236\u6a21\u5f0f\u6253\u5f00\uff08\u53ef\u4ee5\u4e0e\u5176\u4ed6\u6a21\u5f0f\u4e00\u8d77\u4f7f\u7528\uff0c\u5982 <\/span><span style=\"color: #CE9178\">&#39;rb&#39;<\/span><span style=\"color: #D4D4D4\">\u3001<\/span><span style=\"color: #CE9178\">&#39;wb&#39;<\/span><span style=\"color: #D4D4D4\">\uff09\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #CE9178\">&#39;t&#39;<\/span><span style=\"color: #D4D4D4\">: \u4ee5\u6587\u672c\u6a21\u5f0f\u6253\u5f00\uff08\u9ed8\u8ba4\uff0c\u4e0e\u5176\u4ed6\u6a21\u5f0f\u7ec4\u5408\u4f7f\u7528\uff0c\u5982 <\/span><span style=\"color: #CE9178\">&#39;rt&#39;<\/span><span style=\"color: #D4D4D4\">\uff09\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #CE9178\">&#39;x&#39;<\/span><span style=\"color: #D4D4D4\">: \u4ee5\u72ec\u5360\u521b\u5efa\u6a21\u5f0f\u6253\u5f00\uff0c\u6587\u4ef6\u4e0d\u5b58\u5728\u5219\u521b\u5efa\uff0c\u5b58\u5728\u5219\u5f15\u53d1\u9519\u8bef\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #CE9178\">&#39;+&#39;<\/span><span style=\"color: #D4D4D4\">: \u6253\u5f00\u6587\u4ef6\u8fdb\u884c\u66f4\u65b0\uff08\u8bfb\u548c\u5199\uff09\uff0c\u53ef\u4ee5\u4e0e\u5176\u4ed6\u6a21\u5f0f\u7ec4\u5408\u4f7f\u7528\uff0c\u5982 <\/span><span style=\"color: #CE9178\">&#39;r+&#39;<\/span><span style=\"color: #D4D4D4\">\u3001<\/span><span style=\"color: #CE9178\">&#39;w+&#39;<\/span><span style=\"color: #D4D4D4\"> \u7b49\u3002<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5e38\u89c1\u7528\u6cd5<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">with<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">open<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;example.txt&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;r&#39;<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #C586C0\">as<\/span><span style=\"color: #D4D4D4\"> file:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    content = file.read()<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(content)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5199\u5165\u6587\u4ef6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">with<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">open<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;example.txt&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;w&#39;<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #C586C0\">as<\/span><span style=\"color: #D4D4D4\"> file:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    file.write(<\/span><span style=\"color: #CE9178\">&#39;Hello, World!&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u8ffd\u52a0\u5199\u5165\u6587\u4ef6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">with<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">open<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;example.txt&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;a&#39;<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #C586C0\">as<\/span><span style=\"color: #D4D4D4\"> file:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    file.write(<\/span><span style=\"color: #CE9178\">&#39;<\/span><span style=\"color: #D7BA7D\">\\n<\/span><span style=\"color: #CE9178\">Appending this line.&#39;<\/span><span style=\"color: #D4D4D4\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u9010\u884c\u8bfb\u53d6\u6587\u4ef6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">with<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #DCDCAA\">open<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;example.txt&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;r&#39;<\/span><span style=\"color: #D4D4D4\">) <\/span><span style=\"color: #C586C0\">as<\/span><span style=\"color: #D4D4D4\"> file:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> line <\/span><span style=\"color: #C586C0\">in<\/span><span style=\"color: #D4D4D4\"> file:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        <\/span><span style=\"color: #DCDCAA\">print<\/span><span style=\"color: #D4D4D4\">(line.strip())  <\/span><span style=\"color: #6A9955\"># \u53bb\u9664\u6362\u884c\u7b26<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u4f7f\u7528 with open(...) as \u662f\u63a8\u8350\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5728 with \u5757\u7ed3\u675f\u65f6\u81ea\u52a8\u5173\u95ed\u6587\u4ef6\uff0c\u9632\u6b62\u8d44\u6e90\u6cc4\u6f0f\u3002<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u5982\u679c\u4e0d\u4f7f\u7528with open\uff0c\u76f4\u63a5f = open()\uff0c\u5219\u9700\u8981f.close()\u624b\u52a8\u5173\u95ed<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># \u6b64\u5916open()\u8fd8\u53ef\u4ee5\u52a0\u4e0a encoding=&#39;utf-8&#39;\u53c2\u6570\uff0c\u4ee5\u9632\u6b62\u7f16\u7801\u95ee\u9898<\/span><\/span><\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7528Python\u505a\u673a\u8bd5\u9898\u7684\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6 \u8f93\u5165\u8f93\u51fa\u90e8\u5206 \u6570\u636e\u5904\u7406\u90e8\u5206 \u6392\u5e8f \u5bb9\u5668\u76f8\u5173 \u5f02\u5e38\u5904\u7406 \u9762\u5411\u5bf9\u8c61\u57fa\u7840 \u53c2\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-45","post","type-post","status-publish","format-standard","hentry","category-4"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09 - LeezP\u2018s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/leezp.top\/?p=45\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09 - LeezP\u2018s Blog\" \/>\n<meta property=\"og:description\" content=\"\u7528Python\u505a\u673a\u8bd5\u9898\u7684\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6 \u8f93\u5165\u8f93\u51fa\u90e8\u5206 \u6570\u636e\u5904\u7406\u90e8\u5206 \u6392\u5e8f \u5bb9\u5668\u76f8\u5173 \u5f02\u5e38\u5904\u7406 \u9762\u5411\u5bf9\u8c61\u57fa\u7840 \u53c2\u6570 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/leezp.top\/?p=45\" \/>\n<meta property=\"og:site_name\" content=\"LeezP\u2018s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-14T13:23:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-15T05:38:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png\" \/>\n<meta name=\"author\" content=\"LeezPayne\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"LeezPayne\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/leezp.top\/?p=45#article\",\"isPartOf\":{\"@id\":\"https:\/\/leezp.top\/?p=45\"},\"author\":{\"name\":\"LeezPayne\",\"@id\":\"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13\"},\"headline\":\"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09\",\"datePublished\":\"2023-10-14T13:23:01+00:00\",\"dateModified\":\"2024-10-15T05:38:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/leezp.top\/?p=45\"},\"wordCount\":253,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13\"},\"image\":{\"@id\":\"https:\/\/leezp.top\/?p=45#primaryimage\"},\"thumbnailUrl\":\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png\",\"articleSection\":[\"\u7b97\u6cd5\u4e0e\u7b14\u8bd5\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/leezp.top\/?p=45#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/leezp.top\/?p=45\",\"url\":\"https:\/\/leezp.top\/?p=45\",\"name\":\"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09 - LeezP\u2018s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/leezp.top\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/leezp.top\/?p=45#primaryimage\"},\"image\":{\"@id\":\"https:\/\/leezp.top\/?p=45#primaryimage\"},\"thumbnailUrl\":\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png\",\"datePublished\":\"2023-10-14T13:23:01+00:00\",\"dateModified\":\"2024-10-15T05:38:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/leezp.top\/?p=45#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/leezp.top\/?p=45\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/leezp.top\/?p=45#primaryimage\",\"url\":\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image.png\",\"contentUrl\":\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image.png\",\"width\":1284,\"height\":681},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/leezp.top\/?p=45#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/leezp.top\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/leezp.top\/#website\",\"url\":\"https:\/\/leezp.top\/\",\"name\":\"LeezP\u2018s Blog | \u674e\u5b50\u76ae\u7684\u535a\u5ba2\",\"description\":\"\u674e\u5b50\u76ae\u7684\u535a\u5ba2\",\"publisher\":{\"@id\":\"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/leezp.top\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13\",\"name\":\"LeezPayne\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/leezp.top\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/Plum-Ext.png\",\"contentUrl\":\"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/Plum-Ext.png\",\"width\":720,\"height\":720,\"caption\":\"LeezPayne\"},\"logo\":{\"@id\":\"https:\/\/leezp.top\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/leezp.top\"],\"url\":\"https:\/\/leezp.top\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09 - LeezP\u2018s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/leezp.top\/?p=45","og_locale":"zh_CN","og_type":"article","og_title":"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09 - LeezP\u2018s Blog","og_description":"\u7528Python\u505a\u673a\u8bd5\u9898\u7684\u4e00\u4e9b\u57fa\u7840\u77e5\u8bc6 \u8f93\u5165\u8f93\u51fa\u90e8\u5206 \u6570\u636e\u5904\u7406\u90e8\u5206 \u6392\u5e8f \u5bb9\u5668\u76f8\u5173 \u5f02\u5e38\u5904\u7406 \u9762\u5411\u5bf9\u8c61\u57fa\u7840 \u53c2\u6570 [&hellip;]","og_url":"https:\/\/leezp.top\/?p=45","og_site_name":"LeezP\u2018s Blog","article_published_time":"2023-10-14T13:23:01+00:00","article_modified_time":"2024-10-15T05:38:24+00:00","og_image":[{"url":"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png","type":"","width":"","height":""}],"author":"LeezPayne","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"LeezPayne","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/leezp.top\/?p=45#article","isPartOf":{"@id":"https:\/\/leezp.top\/?p=45"},"author":{"name":"LeezPayne","@id":"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13"},"headline":"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09","datePublished":"2023-10-14T13:23:01+00:00","dateModified":"2024-10-15T05:38:24+00:00","mainEntityOfPage":{"@id":"https:\/\/leezp.top\/?p=45"},"wordCount":253,"commentCount":0,"publisher":{"@id":"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13"},"image":{"@id":"https:\/\/leezp.top\/?p=45#primaryimage"},"thumbnailUrl":"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png","articleSection":["\u7b97\u6cd5\u4e0e\u7b14\u8bd5"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/leezp.top\/?p=45#respond"]}]},{"@type":"WebPage","@id":"https:\/\/leezp.top\/?p=45","url":"https:\/\/leezp.top\/?p=45","name":"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09 - LeezP\u2018s Blog","isPartOf":{"@id":"https:\/\/leezp.top\/#website"},"primaryImageOfPage":{"@id":"https:\/\/leezp.top\/?p=45#primaryimage"},"image":{"@id":"https:\/\/leezp.top\/?p=45#primaryimage"},"thumbnailUrl":"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image-1024x543.png","datePublished":"2023-10-14T13:23:01+00:00","dateModified":"2024-10-15T05:38:24+00:00","breadcrumb":{"@id":"https:\/\/leezp.top\/?p=45#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/leezp.top\/?p=45"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/leezp.top\/?p=45#primaryimage","url":"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image.png","contentUrl":"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/image.png","width":1284,"height":681},{"@type":"BreadcrumbList","@id":"https:\/\/leezp.top\/?p=45#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/leezp.top\/"},{"@type":"ListItem","position":2,"name":"Python\u57fa\u7840\u77e5\u8bc6\uff08\u673a\u8bd5\u590d\u4e60\u7528\uff09"}]},{"@type":"WebSite","@id":"https:\/\/leezp.top\/#website","url":"https:\/\/leezp.top\/","name":"LeezP\u2018s Blog | \u674e\u5b50\u76ae\u7684\u535a\u5ba2","description":"\u674e\u5b50\u76ae\u7684\u535a\u5ba2","publisher":{"@id":"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/leezp.top\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/leezp.top\/#\/schema\/person\/74a8eae3251b96c500cb907559caad13","name":"LeezPayne","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/leezp.top\/#\/schema\/person\/image\/","url":"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/Plum-Ext.png","contentUrl":"https:\/\/leezp.top\/wp-content\/uploads\/2023\/10\/Plum-Ext.png","width":720,"height":720,"caption":"LeezPayne"},"logo":{"@id":"https:\/\/leezp.top\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/leezp.top"],"url":"https:\/\/leezp.top\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/leezp.top\/index.php?rest_route=\/wp\/v2\/posts\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/leezp.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/leezp.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/leezp.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/leezp.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45"}],"version-history":[{"count":63,"href":"https:\/\/leezp.top\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions"}],"predecessor-version":[{"id":250,"href":"https:\/\/leezp.top\/index.php?rest_route=\/wp\/v2\/posts\/45\/revisions\/250"}],"wp:attachment":[{"href":"https:\/\/leezp.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/leezp.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/leezp.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}