{"id":1108,"date":"2019-10-20T22:20:05","date_gmt":"2019-10-20T14:20:05","guid":{"rendered":"https:\/\/www.ku88.xyz\/?p=1108"},"modified":"2019-10-20T02:22:44","modified_gmt":"2019-10-19T18:22:44","slug":"whats-new-in-python-3-8","status":"publish","type":"post","link":"https:\/\/www.ku88.xyz\/?p=1108","title":{"rendered":"What&#8217;s New in Python 3.8"},"content":{"rendered":"\n<p>Python \u57282019\u5e7410\u670814\u65e5 \u91cb\u51fa\u4e863.8\u7684\u7248\u672c\uff0c\u9177\u7238\u770b\u4e86\u770b\u65b0\u7684\u7279\u8272\uff0c\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5fc3\u5f97\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" loading=\"lazy\" width=\"725\" height=\"475\" src=\"https:\/\/ku88.xyz\/wordpress\/wp-content\/uploads\/2019\/10\/PIXNIO-723078-725x475.jpeg\" alt=\"\" class=\"wp-image-1109\" srcset=\"https:\/\/www.ku88.xyz\/wp-content\/uploads\/2019\/10\/PIXNIO-723078-725x475.jpeg 725w, https:\/\/www.ku88.xyz\/wp-content\/uploads\/2019\/10\/PIXNIO-723078-725x475-300x197.jpeg 300w, https:\/\/www.ku88.xyz\/wp-content\/uploads\/2019\/10\/PIXNIO-723078-725x475-600x393.jpeg 600w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/figure>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"%E6%B5%B7%E8%B1%A1%E8%A1%A8%E9%81%94%E5%BC%8F_%EF%BC%9A%EF%BC%88Assignment_expressions%EF%BC%89\"><\/span>\u6d77\u8c61\u8868\u9054\u5f0f \uff1a=\uff08Assignment expressions\uff09<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6d77\u8c61\u8868\u9054\u5f0f\uff08\u50cf\u5f62\uff09\u7528\u4f86\u5728\u4e00\u5927\u4e32\u7684\u8868\u9054\u5f0f\u4e2d\u7d66\u4e88\u8b8a\u6578\u503c\u3002<br>\u9019\u73a9\u610f\u8aaa\u5be6\u5728\u9084\u771f\u7684\u883b\u6709\u8da3\u7684\u3002\u883b\u5e38\u78b0\u5230\u7684\u4f8b\u5b50\u662f\u8981print\u7684\u6771\u897f\u8207\u9577\u5ea6\u6709\u95dc\u3002\u8b93\u6211\u5011\u770b\u770b\u4ee5\u4e0b\u5b98\u65b9\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (n := len(a)) > 10:\n    print(f\"List is too long ({n} elements, expected &lt;= 10)\")<\/code><\/pre>\n\n\n\n<p>\u4ee5\u524d\u5fc5\u9700\u8981\u5728\u5224\u65b7\u5f0f\u524d\u5148\u591a\u5beb\u4e00\u884c n = len(a)\uff0c\u624d\u80fd\u5c0dn\u9032\u884c\u6bd4\u8f03\u3002\u73fe\u5728\u5c31\u80fd\u5920\u5728\u5224\u65b7\u5f0f\u57f7\u884c\u7684\u540c\u6642\u7d66\u5b9a\u8b8a\u6578\u503c\u3002\u4f46\u8981\u5c0f\u5fc3\u56e0\u70ba\u7c21\u4fbf\u537b\u7d66\u5225\u4eba\u5e36\u4f86\u4e0d\u4fbf\uff08\u5c0d\u65bc\u770b\u4e0d\u61c2\u7684\u4eba\u4f86\u8aaa\uff09<\/p>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"%E4%BD%8D%E7%BD%AE%E5%8F%83%E6%95%B8_%E8%88%87_%EF%BC%88Positional-only_parameters%EF%BC%89\"><\/span>\u4f4d\u7f6e\u53c3\u6578 \/ \u8207 * \uff08Positional-only parameters\uff09<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5728\u5b9a\u7fa9\u51fd\u6578\u6642\uff0c\u591a\u500b\u9019\u500b\u4f4d\u7f6e\u53c3\u6578\u7684\u4f7f\u7528\u3002\u4e00\u6a23\u662f\u5b98\u65b9\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def f(a, b, \/, c, d, *, e, f):\n    print(a, b, c, d, e, f)<\/code><\/pre>\n\n\n\n<p>a\u8207b\u5c31\u6703\u88ab\u9650\u5236\u70ba\u50c5\u4f7f\u7528\u4f4d\u7f6e\u7684\u53c3\u6578\uff0cc\u8207d\u5247\u53ef\u4ee5\u662f\u4f4d\u7f6e\u53c3\u6578\u6216\u95dc\u9375\u5b57\u53c3\u6578\uff0ce\u8ddff\u5247\u9650\u5b9a\u70ba\u95dc\u9375\u5b57\u53c3\u6578\u3002\u4ee5\u4e0b\u662f\u6b64\u51fd\u5f0f\u7684\u5b98\u65b9\u7684\u7bc4\u4f8b\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>f(10, 20, 30, d=40, e=50, f=60)<\/code><\/pre>\n\n\n\n<p>\u4f7f\u7528\u7684\u4f8b\u5b50\u5305\u542b<br>\uff0e\u6a21\u64ecC\u8a9e\u8a00\u7684\u51fd\u5f0f\u884c\u70ba\uff08\u6c92\u6709\u95dc\u9375\u5b57\u53c3\u6578\uff09<br>\u2027\u589e\u52a0\u53ef\u8b80\u6027\uff08\u6709\u4e9b\u51fd\u5f0f\u52a0\u4e86\u95dc\u9375\u5b57\u53c3\u6578\u53cd\u800c\u5f71\u97ff\u53ef\u8b80\u6027\uff09<br>\u2027\u964d\u4f4e\u66f4\u6539\u95dc\u9375\u5b57\u53c3\u6578\u540d\u7a31\u7684\u5f71\u97ff\uff08\u7981\u7528\u95dc\u9375\u5b57\u53c3\u6578\uff09<br>\u2027\u91cd\u8907\u4f7f\u7528\u95dc\u9375\u5b57\u53c3\u6578\uff08\u95dc\u9375\u5b57\u53c3\u6578\u7684\u9748\u6d3b\u904b\u7528\uff09<\/p>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"f-string%E5%8A%A0%E5%85%A5%E7%9A%84%E4%BD%BF%E7%94%A8\"><\/span>f-string\u52a0\u5165=\u7684\u4f7f\u7528<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e4b\u524d\u9177\u7238\u5176\u5be6\u9084\u662f\u6700\u5e38\u4ee5.format\u7684\u65b9\u5f0f\u4f86\u9032\u884c\u5b57\u4e32\u7684\u8b8a\u6578\u8f38\u51fa\uff08\u9019\u4e9b\u5e74\u4f86\u591a\u6253\u4e86\u597d\u591a\u5b57\u554a\u2026\uff09\uff0c\u6709\u4e86f-string\u4e4b\u5f8c\uff0c\u6703\u5c11\u4e86\u5f88\u591a\u4ee5\u4e0b\u5e38\u898b\u7684\u540c\u540d\u8b8a\u6578\u8f38\u51fa\u65b9\u5f0f\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a=5\nb=6\nprint('{a} and {b}'.format(a=a, b=b)) #\u5225\u518d\u7528\u5566~\n#\u6709\u4e86f-string\u4e4b\u5f8c\nprin(f'{a} and {b}) #\u77ed\u5c11\u7cbe\u5be6~\n#\u57283.8\u7248\u52a0\u5165=\u4e4b\u5f8c\nprint(f'{a=} and {b=}') #\u589e\u52a0print\u7684\u53ef\u8b80\u6027\u3001\u65b9\u4fbfdebug\n#\u4e0d\u7136\u4ee5\u524d\u8981\u9019\u6a23\u5beb\nprint(f'a={a} and b={b}') #\u9577\u4e00\u9ede\u9ede\uff0c\u6709\u9ede\u540c\u540d\u8b8a\u6578\u8f38\u51fa\u7684\u611f\u89ba<\/code><\/pre>\n\n\n\n<h2><span class=\"ez-toc-section\" id=\"pickle_protocol_5\"><\/span>pickle protocol 5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4e0d\u77e5\u9053\u6709\u4ec0\u9ebc\u597d\u8655\uff0c\u4f46\u65b0\u7684\u61c9\u8a72\u6bd4\u8f03\u597d\u5427\u2026\uff08\u6c57\u3002<\/p>\n\n\n\n<p>\u8a73\u7d30\u7684\u89e3\u91cb\u90e8\u4efd\u7576\u7136\u9084\u662f\u8981\u53c3\u95b1\u5b98\u7db2\u56c9~ \u8b1d\u8b1d\u6536\u770b<br><a href=\"https:\/\/docs.python.org\/3\/whatsnew\/3.8.html\">https:\/\/docs.python.org\/3\/whatsnew\/3.8.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u57282019\u5e7410\u670814\u65e5 \u91cb\u51fa\u4e863.8\u7684\u7248\u672c\uff0c\u9177\u7238\u770b\u4e86\u770b\u65b0\u7684\u7279\u8272\uff0c\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5fc3\u5f97\u3002 \u6d77\u8c61\u8868\u9054\u5f0f \uff1a=\uff08Assignment expressions\uff09 \u6d77\u8c61\u8868\u9054\u5f0f\uff08\u50cf\u5f62\uff09\u7528\u4f86\u5728\u4e00\u5927\u4e32\u7684\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,14,25],"tags":[17,67],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[]}},"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":"","woocommerce_thumbnail":"","woocommerce_single":"","woocommerce_gallery_thumbnail":""},"post_excerpt_stackable":"<p>Python \u57282019\u5e7410\u670814\u65e5 \u91cb\u51fa\u4e863.8\u7684\u7248\u672c\uff0c\u9177\u7238\u770b\u4e86\u770b\u65b0\u7684\u7279\u8272\uff0c\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5fc3\u5f97\u3002 \u6d77\u8c61\u8868\u9054\u5f0f \uff1a=\uff08Assignment expressions\uff09 \u6d77\u8c61\u8868\u9054\u5f0f\uff08\u50cf\u5f62\uff09\u7528\u4f86\u5728\u4e00\u5927\u4e32\u7684&#8230;<\/p>\n","category_list":"<a href=\"https:\/\/www.ku88.xyz\/?cat=12\" rel=\"category\">Python<\/a>, <a href=\"https:\/\/www.ku88.xyz\/?cat=14\" rel=\"category\">PythonLife<\/a>, <a href=\"https:\/\/www.ku88.xyz\/?cat=25\" rel=\"category\">PythonTeach<\/a>","author_info":{"name":"ku88","url":"https:\/\/www.ku88.xyz\/?author=1"},"comments_num":"0 comments","featured_image_urls_v2":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":"","woocommerce_thumbnail":"","woocommerce_single":"","woocommerce_gallery_thumbnail":""},"post_excerpt_stackable_v2":"<p>Python \u57282019\u5e7410\u670814\u65e5 \u91cb\u51fa\u4e863.8\u7684\u7248\u672c\uff0c\u9177\u7238\u770b\u4e86\u770b\u65b0\u7684\u7279\u8272\uff0c\u8ddf\u5927\u5bb6\u5206\u4eab\u4e00\u4e0b\u5fc3\u5f97\u3002 \u6d77\u8c61\u8868\u9054\u5f0f \uff1a=\uff08Assignment expressions\uff09 \u6d77\u8c61\u8868\u9054\u5f0f\uff08\u50cf\u5f62\uff09\u7528\u4f86\u5728\u4e00\u5927\u4e32\u7684&#8230;<\/p>\n","category_list_v2":"<a href=\"https:\/\/www.ku88.xyz\/?cat=12\" rel=\"category\">Python<\/a>, <a href=\"https:\/\/www.ku88.xyz\/?cat=14\" rel=\"category\">PythonLife<\/a>, <a href=\"https:\/\/www.ku88.xyz\/?cat=25\" rel=\"category\">PythonTeach<\/a>","author_info_v2":{"name":"ku88","url":"https:\/\/www.ku88.xyz\/?author=1"},"comments_num_v2":"0 comments","_links":{"self":[{"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1108"}],"collection":[{"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1108"}],"version-history":[{"count":2,"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1108\/revisions"}],"predecessor-version":[{"id":1111,"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1108\/revisions\/1111"}],"wp:attachment":[{"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ku88.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}