{"id":60052,"date":"2026-01-14T22:05:22","date_gmt":"2026-01-14T14:05:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/60052.html"},"modified":"2026-01-14T22:05:22","modified_gmt":"2026-01-14T14:05:22","slug":"python-3-8-%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%9a%e6%b7%b1%e5%85%a5%e7%90%86%e8%a7%a3%e5%b9%b6%e6%8e%8c%e6%8f%a1%e8%b5%8b%e5%80%bc%e8%a1%a8%e8%be%be%e5%bc%8f%ef%bc%88the-walrus-operator%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/60052.html","title":{"rendered":"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09"},"content":{"rendered":"<\/p>\n<h4><font color=\"orange\" size=\"5\">\u76ee\u5f55<\/font><\/h4>\n<ul>\n<li>\n<ul>\n<li>Python 3.8 \u65b0\u7279\u6027&#xff1a;\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff08;The Walrus Operator&#xff09;<\/li>\n<li>1. \u4ec0\u4e48\u662f\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1f;\u6253\u7834\u4f20\u7edf\u7684\u201c:&#061;\u201d<\/li>\n<li>2. \u6838\u5fc3\u5e94\u7528\u573a\u666f&#xff1a;\u8ba9\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u66f4\u9ad8\u6548<\/li>\n<li>\n<ul>\n<li>2.1 &#096;while&#096; \u5faa\u73af\u4e2d\u7684 &#096;read()&#096; \u6a21\u5f0f<\/li>\n<li>2.2 \u5217\u8868\u63a8\u5bfc\u5f0f\u4e0e &#096;walrus&#096; \u7684\u5a01\u529b<\/li>\n<li>2.3 &#096;if&#096; \u5206\u652f\u4e2d\u7684\u590d\u6742\u5339\u914d<\/li>\n<\/ul>\n<\/li>\n<li>3. \u7406\u89e3\u4f5c\u7528\u57df&#xff1a;\u5b83\u4e0d\u4ec5\u4ec5\u662f\u201c\u5c40\u90e8\u53d8\u91cf\u201d<\/li>\n<li>\n<ul>\n<li>3.1 \u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u65b0\u4f5c\u7528\u57df<\/li>\n<li>3.2 \u5faa\u73af\u4e0e &#096;if&#096; \u5757\u7684\u4f5c\u7528\u57df\u9677\u9631<\/li>\n<\/ul>\n<\/li>\n<li>4. \u4ec0\u4e48\u65f6\u5019\u4e0d\u5e94\u8be5\u4f7f\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1f;<\/li>\n<li>5. \u603b\u7ed3\u4e0e\u5c55\u671b<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u4e13\u680f\u5bfc\u8bfb <\/p>\n<ul>\n<li>\n<h6>&#x1f338; \u6b22\u8fce\u6765\u5230Python\u529e\u516c\u81ea\u52a8\u5316\u4e13\u680f\u2014Python\u5904\u7406\u529e\u516c\u95ee\u9898&#xff0c;\u89e3\u653e\u60a8\u7684\u53cc\u624b <\/h6>\n<\/li>\n<li>\n<h6> &#x1f3f3;\ufe0f\u200d&#x1f308; \u4e2a\u4eba\u535a\u5ba2\u4e3b\u9875&#xff1a;\u8bf7\u70b9\u51fb\u2014\u2014&gt; \u4e2a\u4eba\u7684\u535a\u5ba2\u4e3b\u9875 \u6c42\u6536\u85cf <\/h6>\n<\/li>\n<li>\n<h6> &#x1f3f3;\ufe0f\u200d&#x1f308; Github\u4e3b\u9875&#xff1a;\u8bf7\u70b9\u51fb\u2014\u2014&gt; Github\u4e3b\u9875 \u6c42Star\u2b50 <\/h6>\n<\/li>\n<li>\n<h6> &#x1f3f3;\ufe0f\u200d&#x1f308; \u77e5\u4e4e\u4e3b\u9875&#xff1a;\u8bf7\u70b9\u51fb\u2014\u2014&gt; \u77e5\u4e4e\u4e3b\u9875 \u6c42\u5173\u6ce8 <\/h6>\n<\/li>\n<li>\n<h6> &#x1f3f3;\ufe0f\u200d&#x1f308; CSDN\u535a\u5ba2\u4e3b\u9875&#xff1a;\u8bf7\u70b9\u51fb\u2014\u2014&gt; CSDN\u7684\u535a\u5ba2\u4e3b\u9875 \u6c42\u5173\u6ce8 <\/h6>\n<\/li>\n<li>\n<h6> &#x1f44d; \u8be5\u7cfb\u5217\u6587\u7ae0\u4e13\u680f&#xff1a;\u8bf7\u70b9\u51fb\u2014\u2014&gt;Python\u529e\u516c\u81ea\u52a8\u5316\u4e13\u680f \u6c42\u8ba2\u9605 <\/h6>\n<\/li>\n<li>\n<h6> &#x1f577; \u6b64\u5916\u8fd8\u6709\u722c\u866b\u4e13\u680f&#xff1a;\u8bf7\u70b9\u51fb\u2014\u2014&gt;Python\u722c\u866b\u57fa\u7840\u4e13\u680f \u6c42\u8ba2\u9605 <\/h6>\n<\/li>\n<li>\n<h6> &#x1f4d5; \u6b64\u5916\u8fd8\u6709python\u57fa\u7840\u4e13\u680f&#xff1a;\u8bf7\u70b9\u51fb\u2014\u2014&gt;Python\u57fa\u7840\u5b66\u4e60\u4e13\u680f \u6c42\u8ba2\u9605 <\/h6>\n<\/li>\n<li>\n<h6> \u6587\u7ae0\u4f5c\u8005\u6280\u672f\u548c\u6c34\u5e73\u6709\u9650&#xff0c;\u5982\u679c\u6587\u4e2d\u51fa\u73b0\u9519\u8bef&#xff0c;\u5e0c\u671b\u5927\u5bb6\u80fd\u6307\u6b63&#x1f64f; <\/h6>\n<\/li>\n<li>\n<h6> \u2764\ufe0f \u6b22\u8fce\u5404\u4f4d\u4f6c\u5173\u6ce8&#xff01; \u2764\ufe0f <\/h6>\n<\/li>\n<\/ul>\n<\/h4>\n<h3>Python 3.8 \u65b0\u7279\u6027&#xff1a;\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff08;The Walrus Operator&#xff09;<\/h3>\n<h3>1. \u4ec0\u4e48\u662f\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1f;\u6253\u7834\u4f20\u7edf\u7684\u201c:&#061;\u201d<\/h3>\n<p>\u5728 Python 3.8 \u6b63\u5f0f\u5f15\u5165\u8d4b\u503c\u8868\u8fbe\u5f0f\u4e4b\u524d&#xff0c;\u6211\u4eec\u4e60\u60ef\u5c06\u8d4b\u503c\u8bed\u53e5&#xff08;&#061;&#xff09;\u4e25\u683c\u533a\u5206\u4e8e\u8868\u8fbe\u5f0f\u3002\u8d4b\u503c\u8bed\u53e5\u7528\u4e8e\u6539\u53d8\u53d8\u91cf\u72b6\u6001&#xff0c;\u800c\u8868\u8fbe\u5f0f\u7528\u4e8e\u8ba1\u7b97\u5e76\u8fd4\u56de\u503c\u3002\u8fd9\u79cd\u6cfe\u6e2d\u5206\u660e\u7684\u754c\u9650\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u663e\u5f97\u5c24\u4e3a\u50f5\u786c&#xff0c;\u5bfc\u81f4\u6211\u4eec\u4e0d\u5f97\u4e0d\u7f16\u5199\u91cd\u590d\u6216\u5197\u4f59\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff0c;\u5b98\u65b9\u4ee3\u53f7 \u201cThe Walrus Operator\u201d&#xff08;\u6d77\u8c61\u8fd0\u7b97\u7b26&#xff09;&#xff0c;\u5373 :&#061;&#xff0c;\u5b83\u7684\u51fa\u73b0\u6253\u7834\u4e86\u8fd9\u4e00\u5e38\u89c4\u3002\u5b83\u5141\u8bb8\u6211\u4eec\u5728\u8868\u8fbe\u5f0f\u5185\u90e8\u76f4\u63a5\u8fdb\u884c\u53d8\u91cf\u8d4b\u503c&#xff0c;\u5e76\u8fd4\u56de\u6240\u8d4b\u7684\u503c\u3002<\/p>\n<p>\u770b\u4e00\u4e2a\u6700\u76f4\u89c2\u7684\u5bf9\u6bd4&#xff1a;<\/p>\n<p>\u4f20\u7edf\u5199\u6cd5&#xff08;Python 3.7 \u53ca\u4ee5\u524d&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u6211\u4eec\u9700\u8981\u5148\u8ba1\u7b97\u957f\u5ea6&#xff0c;\u518d\u5224\u65ad\u957f\u5ea6\u662f\u5426\u5927\u4e8e 0<\/span><br \/>\ntext <span class=\"token operator\">&#061;<\/span> get_data<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Received <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span><span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>text<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> characters.&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u91cc len(text) \u88ab\u8c03\u7528\u4e86\u4e24\u6b21\u3002\u867d\u7136\u5728\u8fd9\u4e2a\u7b80\u5355\u4f8b\u5b50\u4e2d\u6027\u80fd\u5f71\u54cd\u5fae\u4e4e\u5176\u5fae&#xff0c;\u4f46\u5728\u66f4\u590d\u6742\u7684\u903b\u8f91\u4e2d&#xff0c;\u91cd\u590d\u8ba1\u7b97\u6216\u91cd\u590d\u8c03\u7528\u51fd\u6570\u662f\u4e0d\u4f18\u96c5\u7684\u3002<\/p>\n<p>\u4f7f\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff08;Python 3.8&#043;&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\"># :&#061; \u76f4\u63a5\u5c06\u8ba1\u7b97\u7ed3\u679c\u8d4b\u503c\u7ed9 n&#xff0c;\u5e76\u8fd4\u56de n \u7684\u503c\u7528\u4e8e\u5224\u65ad<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>n <span class=\"token operator\">:&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>get_data<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Received <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>n<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> characters.&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u901a\u8fc7 :&#061;&#xff0c;\u6211\u4eec\u6210\u529f\u5c06\u8d4b\u503c\u64cd\u4f5c\u5d4c\u5165\u5230\u4e86\u8868\u8fbe\u5f0f\u4e2d\u3002\u8fd9\u4e0d\u4ec5\u4ec5\u662f\u4ee3\u7801\u884c\u6570\u7684\u51cf\u5c11&#xff0c;\u66f4\u662f\u903b\u8f91\u6d41\u7684\u6539\u53d8\u2014\u2014\u5b83\u89e3\u51b3\u4e86\u201c\u6211\u60f3\u5728\u4f7f\u7528\u4e00\u4e2a\u53d8\u91cf\u4e4b\u524d\u5148\u8ba1\u7b97\u5b83&#xff0c;\u4f46\u53c8\u4e0d\u60f3\u628a\u5b83\u653e\u5728\u4e0a\u4e00\u884c\u201d\u7684\u75db\u70b9\u3002<\/p>\n<h3>2. \u6838\u5fc3\u5e94\u7528\u573a\u666f&#xff1a;\u8ba9\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u66f4\u9ad8\u6548<\/h3>\n<p>\u8d4b\u503c\u8868\u8fbe\u5f0f\u5e76\u975e\u4e3a\u4e86\u70ab\u6280&#xff0c;\u5b83\u5728\u7279\u5b9a\u7684\u9ad8\u9891\u573a\u666f\u4e0b\u80fd\u663e\u8457\u63d0\u5347\u4ee3\u7801\u8d28\u91cf\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<h4>2.1 while \u5faa\u73af\u4e2d\u7684 read() \u6a21\u5f0f<\/h4>\n<p>\u5904\u7406\u6587\u4ef6\u8bfb\u53d6\u6216\u7f51\u7edc\u6d41\u65f6&#xff0c;\u7ecf\u5178\u7684 while \u5faa\u73af\u5199\u6cd5\u901a\u5e38\u662f\u8fd9\u6837\u7684&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u4f20\u7edf\u5199\u6cd5<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token boolean\">True<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    chunk <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">file<\/span><span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token number\">8192<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> chunk<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">break<\/span><br \/>\n    process<span class=\"token punctuation\">(<\/span>chunk<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u4f7f\u7528\u6d77\u8c61\u8fd0\u7b97\u7b26&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5c06 chunk \u7684\u8d4b\u503c\u3001\u5224\u65ad\u548c\u5faa\u73af\u903b\u8f91\u538b\u7f29\u5230\u4e00\u884c&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u8d4b\u503c\u8868\u8fbe\u5f0f\u5199\u6cd5<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>chunk <span class=\"token operator\">:&#061;<\/span> <span class=\"token builtin\">file<\/span><span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token number\">8192<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    process<span class=\"token punctuation\">(<\/span>chunk<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u79cd\u5199\u6cd5\u6781\u5176\u63a5\u8fd1 Unix C \u8bed\u8a00\u4e2d\u5e38\u89c1\u7684 while ((n &#061; read(fd, buf, sizeof buf)) &gt; 0) \u6a21\u5f0f&#xff0c;\u5bf9\u4e8e\u4e60\u60ef\u4e86\u5e95\u5c42\u7f16\u7a0b\u7684\u5f00\u53d1\u8005\u6765\u8bf4&#xff0c;\u8fd9\u65e2\u719f\u6089\u53c8\u9ad8\u6548\u3002<\/p>\n<h4>2.2 \u5217\u8868\u63a8\u5bfc\u5f0f\u4e0e walrus \u7684\u5a01\u529b<\/h4>\n<p>\u8fd9\u662f\u8d4b\u503c\u8868\u8fbe\u5f0f\u6700\u80fd\u4f53\u73b0\u201c\u590d\u7528\u8ba1\u7b97\u7ed3\u679c\u201d\u4ef7\u503c\u7684\u5730\u65b9\u3002\u5728 Python 3.8 \u4e4b\u524d&#xff0c;\u5982\u679c\u4f60\u60f3\u5728\u5217\u8868\u63a8\u5bfc\u5f0f\u4e2d\u8fc7\u6ee4\u6389 None \u6216\u8ba1\u7b97\u6210\u672c\u9ad8\u6602\u7684\u51fd\u6570\u7ed3\u679c&#xff0c;\u901a\u5e38\u9700\u8981\u5199\u6210\u8fd9\u6837&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u4f20\u7edf\u5199\u6cd5&#xff1a;\u8c03\u7528\u4e24\u6b21 expensive_func<\/span><br \/>\ndata <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span>x <span class=\"token keyword\">for<\/span> x <span class=\"token keyword\">in<\/span> <span class=\"token punctuation\">[<\/span>expensive_func<span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token keyword\">if<\/span> x <span class=\"token keyword\">is<\/span> <span class=\"token keyword\">not<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>\u6216\u8005\u4e0d\u5f97\u4e0d\u653e\u5f03\u63a8\u5bfc\u5f0f&#xff0c;\u6539\u7528\u666e\u901a\u7684 for \u5faa\u73af\u3002<\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8fd9\u6837\u505a&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u8d4b\u503c\u8868\u8fbe\u5f0f\u5199\u6cd5<\/span><br \/>\ndata <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span>y <span class=\"token keyword\">for<\/span> x <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>y <span class=\"token operator\">:&#061;<\/span> expensive_func<span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">is<\/span> <span class=\"token keyword\">not<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>\u5728\u8fd9\u91cc&#xff0c;expensive_func(x) \u53ea\u88ab\u8c03\u7528\u4e86\u4e00\u6b21\u3002\u6211\u4eec\u5c06\u8ba1\u7b97\u7ed3\u679c\u8d4b\u503c\u7ed9 y&#xff0c;\u7136\u540e\u5728\u540e\u7eed\u7684\u8fc7\u6ee4\u6761\u4ef6\u548c\u6700\u7ec8\u8f93\u51fa\u4e2d\u90fd\u4f7f\u7528\u4e86\u8fd9\u4e2a y\u3002\u8fd9\u5728\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u6602\u8d35\u8ba1\u7b97\u65f6&#xff0c;\u65e2\u4f18\u96c5\u53c8\u5b9e\u7528\u3002<\/p>\n<h4>2.3 if \u5206\u652f\u4e2d\u7684\u590d\u6742\u5339\u914d<\/h4>\n<p>\u5047\u8bbe\u4f60\u6b63\u5728\u5904\u7406\u6b63\u5219\u5339\u914d&#xff1a;<\/p>\n<p><span class=\"token keyword\">import<\/span> re<\/p>\n<p>data <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;Python 3.8 released in 2019&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u4f20\u7edf\u5199\u6cd5<\/span><br \/>\n<span class=\"token keyword\">match<\/span> <span class=\"token operator\">&#061;<\/span> re<span class=\"token punctuation\">.<\/span>search<span class=\"token punctuation\">(<\/span><span class=\"token string\">r&#039;Python (\\\\d\\\\.\\\\d)&#039;<\/span><span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token keyword\">match<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    version <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">match<\/span><span class=\"token punctuation\">.<\/span>group<span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Found version: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>version<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u4f7f\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1a;<\/p>\n<p><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">match<\/span> <span class=\"token operator\">:&#061;<\/span> re<span class=\"token punctuation\">.<\/span>search<span class=\"token punctuation\">(<\/span><span class=\"token string\">r&#039;Python (\\\\d\\\\.\\\\d)&#039;<\/span><span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Found version: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span><span class=\"token keyword\">match<\/span><span class=\"token punctuation\">.<\/span>group<span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u79cd\u5199\u6cd5\u4e0d\u4ec5\u51cf\u5c11\u4e86 match \u53d8\u91cf\u7684\u4e34\u65f6\u6027\u5360\u7528&#xff0c;\u8fd8\u8ba9\u4ee3\u7801\u903b\u8f91\u66f4\u52a0\u7d27\u51d1&#xff0c;\u660e\u786e\u8868\u8fbe\u4e86\u201c\u5982\u679c\u5339\u914d\u5230\u4e86&#xff0c;\u5c31\u6267\u884c\u2026\u2026\u201d\u7684\u610f\u56fe\u3002<\/p>\n<h3>3. \u7406\u89e3\u4f5c\u7528\u57df&#xff1a;\u5b83\u4e0d\u4ec5\u4ec5\u662f\u201c\u5c40\u90e8\u53d8\u91cf\u201d<\/h3>\n<p>\u5728\u4f7f\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f\u65f6&#xff0c;\u6700\u5bb9\u6613\u8ba9\u4eba\u56f0\u60d1\u7684\u662f\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u95ee\u9898\u3002\u8fd9\u662f\u533a\u5206\u65b0\u624b\u548c\u719f\u7ec3\u5f00\u53d1\u8005\u7684\u5173\u952e\u70b9\u3002<\/p>\n<h4>3.1 \u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u65b0\u4f5c\u7528\u57df<\/h4>\n<p>\u5728 Python 3.8 \u4e2d&#xff0c;\u5217\u8868\u63a8\u5bfc\u5f0f&#xff08;\u4ee5\u53ca\u96c6\u5408\u3001\u5b57\u5178\u63a8\u5bfc\u5f0f&#xff09;\u62e5\u6709\u81ea\u5df1\u7684\u72ec\u7acb\u4f5c\u7528\u57df\u3002<\/p>\n<p>x <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;outer&#034;<\/span><br \/>\n<span class=\"token comment\"># \u5728\u63a8\u5bfc\u5f0f\u5185\u90e8\u8d4b\u503c x<\/span><br \/>\na <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span>x <span class=\"token keyword\">for<\/span> x <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">]<\/span> <\/p>\n<p><span class=\"token comment\"># \u5916\u90e8\u7684 x \u4e0d\u53d7\u5f71\u54cd<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u8f93\u51fa: &#034;outer&#034;<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u8f93\u51fa: [0, 1, 2]<\/span><\/p>\n<p>\u5728\u5217\u8868\u63a8\u5bfc\u5f0f\u5185\u90e8\u4f7f\u7528 :&#061; \u8d4b\u503c\u7684\u53d8\u91cf&#xff0c;\u5176\u4f5c\u7528\u57df\u88ab\u9650\u5236\u5728\u63a8\u5bfc\u5f0f\u5185\u90e8&#xff08;\u7c7b\u4f3c\u4e8e\u51fd\u6570\u4f5c\u7528\u57df&#xff09;&#xff0c;\u4e0d\u4f1a\u6cc4\u6f0f\u5230\u5916\u90e8\u3002<\/p>\n<h4>3.2 \u5faa\u73af\u4e0e if \u5757\u7684\u4f5c\u7528\u57df\u9677\u9631<\/h4>\n<p>\u7136\u800c&#xff0c;\u5728\u666e\u901a\u7684 if \u8bed\u53e5\u6216 while \u5faa\u73af\u4e2d&#xff0c;:&#061; \u8d4b\u503c\u7684\u53d8\u91cf\u4f1a\u76f4\u63a5\u6cc4\u6f0f\u5230\u5f53\u524d\u7684\u4f5c\u7528\u57df&#xff08;\u5373\u5305\u542b\u8be5\u8bed\u53e5\u7684\u51fd\u6570\u6216\u5168\u5c40\u4f5c\u7528\u57df&#xff09;\u3002<\/p>\n<p>\u770b\u8fd9\u4e2a\u4f8b\u5b50&#xff1a;<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">demo<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    data <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>n <span class=\"token operator\">:&#061;<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">3<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f&#034;List is too long: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>n<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># n \u5728\u8fd9\u91cc\u4f9d\u7136\u5b58\u5728&#xff01;<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u8f93\u51fa: 5<\/span><\/p>\n<p>\u66f4\u5371\u9669\u7684\u9677\u9631&#xff1a;<\/p>\n<p>y <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">bar<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u8fd9\u91cc\u5e76\u6ca1\u6709\u521b\u5efa\u5c40\u90e8\u53d8\u91cf y&#xff0c;\u800c\u662f\u4fee\u6539\u4e86\u5168\u5c40\u53d8\u91cf y<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>y <span class=\"token operator\">:&#061;<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">pass<\/span><br \/>\nbar<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>y<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u8f93\u51fa: 10 (\u5168\u5c40\u53d8\u91cf\u88ab\u4fee\u6539\u4e86&#xff01;)<\/span><\/p>\n<p>\u6700\u4f73\u5b9e\u8df5\u5efa\u8bae&#xff1a; \u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u526f\u4f5c\u7528&#xff0c;\u5efa\u8bae\u5728\u4f7f\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f\u65f6&#xff1a;<\/p>\n<li>\u603b\u662f\u4f7f\u7528\u62ec\u53f7&#xff1a;(x :&#061; func()) \u662f\u6807\u51c6\u5199\u6cd5&#xff0c;\u867d\u7136\u8bed\u6cd5\u4e0a\u4e0d\u5f3a\u5236&#xff0c;\u4f46\u80fd\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002<\/li>\n<li>\u907f\u514d\u5728\u63a8\u5bfc\u5f0f\u5916\u90e8\u4fee\u6539\u5916\u90e8\u53d8\u91cf&#xff1a;\u9664\u975e\u4f60\u660e\u786e\u77e5\u9053\u81ea\u5df1\u5728\u505a\u4ec0\u4e48&#xff0c;\u5426\u5219\u5c3d\u91cf\u5728 if \u6216 while \u8fd9\u79cd\u5c40\u90e8\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528&#xff0c;\u6216\u8005\u5728\u51fd\u6570\u5185\u90e8\u4f7f\u7528\u3002<\/li>\n<li>\u53d8\u91cf\u547d\u540d\u6e05\u6670&#xff1a;\u4e0d\u8981\u4f7f\u7528 i\u3001j \u7b49\u5bb9\u6613\u6df7\u6dc6\u7684\u77ed\u540d\u79f0&#xff0c;\u4f7f\u7528 match\u3001count\u3001result \u7b49\u5177\u6709\u63cf\u8ff0\u6027\u7684\u540d\u79f0\u3002<\/li>\n<h3>4. \u4ec0\u4e48\u65f6\u5019\u4e0d\u5e94\u8be5\u4f7f\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1f;<\/h3>\n<p>\u867d\u7136\u8d4b\u503c\u8868\u8fbe\u5f0f\u5f88\u5f3a\u5927&#xff0c;\u4f46\u6ee5\u7528\u5b83\u4f1a\u5bfc\u81f4\u4ee3\u7801\u53d8\u5f97\u6666\u6da9\u96be\u61c2\u3002Python \u4e4b\u7236 Guido van Rossum \u6700\u521d\u751a\u81f3\u53cd\u5bf9\u5f15\u5165\u5b83&#xff0c;\u7406\u7531\u5c31\u662f\u62c5\u5fc3\u4ee3\u7801\u53ef\u8bfb\u6027\u4e0b\u964d\u3002<\/p>\n<p>\u4ee5\u4e0b\u60c5\u51b5\u8bf7\u62d2\u7edd\u4f7f\u7528 :&#061;&#xff1a;<\/p>\n<li>\n<p>\u8868\u8fbe\u5f0f\u8fc7\u4e8e\u590d\u6742\u65f6&#xff1a; \u5982\u679c\u8d4b\u503c\u90e8\u5206\u548c\u4f7f\u7528\u90e8\u5206\u903b\u8f91\u8de8\u5ea6\u5f88\u5927&#xff0c;\u5f3a\u884c\u585e\u8fdb\u4e00\u884c\u662f\u53cd\u4eba\u7c7b\u7684\u3002<\/p>\n<p> <span class=\"token comment\"># \u574f\u4ee3\u7801\u793a\u4f8b<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">match<\/span> <span class=\"token operator\">:&#061;<\/span> re<span class=\"token punctuation\">.<\/span>search<span class=\"token punctuation\">(<\/span><span class=\"token string\">r&#039;&#8230;&#039;<\/span><span class=\"token punctuation\">,<\/span> text<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">and<\/span> <span class=\"token punctuation\">(<\/span>result <span class=\"token operator\">:&#061;<\/span> process<span class=\"token punctuation\">(<\/span><span class=\"token keyword\">match<\/span><span class=\"token punctuation\">.<\/span>group<span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">and<\/span> result<span class=\"token punctuation\">.<\/span>is_valid<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><\/p>\n<p>\u8fd9\u79cd\u4ee3\u7801\u5e94\u8be5\u62c6\u5206\u6210\u591a\u884c&#xff0c;\u6216\u8005\u5e72\u8106\u4e0d\u8981\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u4e86\u8d4b\u503c\u800c\u8d4b\u503c&#xff1a; \u5982\u679c\u4f60\u53ea\u662f\u60f3\u5728\u5faa\u73af\u4e2d\u6253\u5370\u8c03\u8bd5\u4fe1\u606f&#xff0c;\u4e0d\u8981\u7528\u5b83\u3002<\/p>\n<p> <span class=\"token comment\"># \u574f\u4ee3\u7801\u793a\u4f8b<\/span><br \/>\n<span class=\"token comment\"># \u867d\u7136\u80fd\u8fd0\u884c&#xff0c;\u4f46\u8ba9\u4eba\u56f0\u60d1<\/span><br \/>\n<span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">:&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">or<\/span> x <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><\/p>\n<p>print \u51fd\u6570\u8fd4\u56de None&#xff0c;\u8fd9\u91cc\u7684 or \u903b\u8f91\u5f88\u5947\u602a\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728 lambda \u4e2d\u4f7f\u7528&#xff1a; Python 3.8 \u4e0d\u5141\u8bb8\u5728 lambda \u4e2d\u4f7f\u7528\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff08;\u867d\u7136\u5728 Python 3.9&#043; \u4e2d\u653e\u5bbd\u4e86\u9650\u5236&#xff0c;\u4f46\u4f9d\u7136\u4e0d\u63a8\u8350&#xff09;\u3002\u5982\u679c\u903b\u8f91\u590d\u6742\u5230\u9700\u8981\u5728 lambda \u91cc\u8d4b\u503c&#xff0c;\u4e0d\u5982\u76f4\u63a5\u5b9a\u4e49\u4e00\u4e2a\u5c40\u90e8\u51fd\u6570\u3002<\/p>\n<\/li>\n<h3>5. \u603b\u7ed3\u4e0e\u5c55\u671b<\/h3>\n<p>\u8d4b\u503c\u8868\u8fbe\u5f0f (:&#061;) \u662f Python \u5411\u8868\u8fbe\u5f0f\u5316\u7f16\u7a0b\u8fc8\u8fdb\u7684\u91cd\u8981\u4e00\u6b65\u3002\u5b83\u4e3b\u8981\u89e3\u51b3\u4e86\u4ee3\u7801\u5197\u4f59\u548c\u8ba1\u7b97\u590d\u7528\u7684\u95ee\u9898\u3002<\/p>\n<p>\u6838\u5fc3\u8981\u70b9\u56de\u987e&#xff1a;<\/p>\n<ul>\n<li>\u8bed\u6cd5&#xff1a;name :&#061; expr&#xff0c;\u8fd4\u56de name \u7684\u503c\u3002<\/li>\n<li>\u4f18\u52bf&#xff1a;\u5728 while \u5faa\u73af\u3001\u5217\u8868\u63a8\u5bfc\u5f0f\u548c if \u5339\u914d\u4e2d\u5927\u5e45\u51cf\u5c11\u4ee3\u7801\u884c\u6570\u548c\u91cd\u590d\u8ba1\u7b97\u3002<\/li>\n<li>\u98ce\u9669&#xff1a;\u6ce8\u610f\u53d8\u91cf\u4f5c\u7528\u57df\u6cc4\u6f0f&#xff0c;\u5c24\u5176\u662f\u5728\u5168\u5c40\u4f5c\u7528\u57df\u6216\u6df7\u5408\u4f7f\u7528\u65f6\u3002<\/li>\n<li>\u539f\u5219&#xff1a;\u4fdd\u6301\u7b80\u5355&#xff0c;\u4e0d\u8981\u4e3a\u4e86\u4f7f\u7528\u800c\u4f7f\u7528&#xff0c;\u4f18\u5148\u8003\u8651\u53ef\u8bfb\u6027\u3002<\/li>\n<\/ul>\n<p>\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff0c;\u610f\u5473\u7740\u4f60\u7684 Python \u5de5\u5177\u7bb1\u91cc\u591a\u4e86\u4e00\u628a\u950b\u5229\u7684\u745e\u58eb\u519b\u5200\u3002\u5728\u9002\u5f53\u7684\u5730\u65b9\u4f7f\u7528\u5b83&#xff0c;\u80fd\u8ba9\u4f60\u7684\u4ee3\u7801\u66f4\u50cf C \u8bed\u8a00\u4e00\u6837\u7d27\u51d1\u9ad8\u6548&#xff0c;\u540c\u65f6\u4fdd\u7559 Python \u7684\u4f18\u96c5\u3002<\/p>\n<p>\u4f60\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d&#xff0c;\u9047\u5230\u8fc7\u54ea\u4e9b\u5fc5\u987b\u91cd\u590d\u8ba1\u7b97\u4e24\u6b21\u53d8\u91cf\u7684\u573a\u666f&#xff1f;\u4f60\u89c9\u5f97\u8d4b\u503c\u8868\u8fbe\u5f0f\u80fd\u89e3\u51b3\u4f60\u7684\u75db\u70b9\u5417&#xff1f;\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u5206\u4eab\u4f60\u7684\u4ee3\u7801\u7247\u6bb5&#xff01;<\/p>\n<h4>\u7ed3\u5c3e <\/p>\n<ul>\n<li>\n<h6>\u5e0c\u671b\u5bf9\u521d\u5b66\u8005\u6709\u5e2e\u52a9&#xff1b;\u81f4\u529b\u4e8e\u529e\u516c\u81ea\u52a8\u5316\u7684\u5c0f\u5c0f\u7a0b\u5e8f\u5458\u4e00\u679a <\/h6>\n<\/li>\n<li>\n<h6>\u5e0c\u671b\u80fd\u5f97\u5230\u5927\u5bb6\u7684\u3010\u2764\ufe0f\u4e00\u4e2a\u514d\u8d39\u5173\u6ce8\u2764\ufe0f\u3011\u611f\u8c22&#xff01; <\/h6>\n<\/li>\n<li>\n<h6>\u6c42\u4e2a &#x1f91e; \u5173\u6ce8 &#x1f91e; &#043;\u2764\ufe0f \u559c\u6b22 \u2764\ufe0f &#043;&#x1f44d; \u6536\u85cf &#x1f44d; <\/h6>\n<\/li>\n<li>\n<h6>\u6b64\u5916\u8fd8\u6709\u529e\u516c\u81ea\u52a8\u5316\u4e13\u680f&#xff0c;\u6b22\u8fce\u5927\u5bb6\u8ba2\u9605&#xff1a;Python\u529e\u516c\u81ea\u52a8\u5316\u4e13\u680f <\/h6>\n<\/li>\n<li>\n<h6>\u6b64\u5916\u8fd8\u6709\u722c\u866b\u4e13\u680f&#xff0c;\u6b22\u8fce\u5927\u5bb6\u8ba2\u9605&#xff1a;Python\u722c\u866b\u57fa\u7840\u4e13\u680f <\/h6>\n<\/li>\n<li>\n<h6>\u6b64\u5916\u8fd8\u6709Python\u57fa\u7840\u4e13\u680f&#xff0c;\u6b22\u8fce\u5927\u5bb6\u8ba2\u9605&#xff1a;Python\u57fa\u7840\u5b66\u4e60\u4e13\u680f <\/h6>\n<\/li>\n<\/ul>\n<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55Python 3.8 \u65b0\u7279\u6027&#xff1a;\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff08;The Walrus Operator&#xff09;1. \u4ec0\u4e48\u662f\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1f;\u6253\u7834\u4f20\u7edf\u7684\u201c:\u201d2. \u6838\u5fc3\u5e94\u7528\u573a\u666f&#xff1a;\u8ba9\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u66f4\u9ad8\u65482.1 while \u5faa\u73af\u4e2d\u7684 read() \u6a21\u5f0f2.2 \u5217\u8868\u63a8\u5bfc\u5f0f\u4e0e walrus \u7684\u5a01\u529b2.3 if \u5206\u652f\u4e2d\u7684\u590d\u6742\u5339\u914d3. \u7406\u89e3\u4f5c\u7528\u57df&#xff1a;\u5b83\u4e0d\u4ec5\u4ec5\u662f\u201c\u5c40\u90e8\u53d8\u91cf\u201d3.1 \u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u65b0\u4f5c\u7528\u57df3.2 \u5faa\u73af\u4e0e if \u5757\u7684\u4f5c<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[6333,6334,6335,1845,81,190],"topic":[],"class_list":{"0":"post-60052","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-python3","8":"tag-python","10":"tag-ipython","12":"tag-190"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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:\/\/www.wsisp.com\/helps\/60052.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55Python 3.8 \u65b0\u7279\u6027&#xff1a;\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff08;The Walrus Operator&#xff09;1. \u4ec0\u4e48\u662f\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1f;\u6253\u7834\u4f20\u7edf\u7684\u201c:\u201d2. \u6838\u5fc3\u5e94\u7528\u573a\u666f&#xff1a;\u8ba9\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u66f4\u9ad8\u65482.1 while \u5faa\u73af\u4e2d\u7684 read() \u6a21\u5f0f2.2 \u5217\u8868\u63a8\u5bfc\u5f0f\u4e0e walrus \u7684\u5a01\u529b2.3 if \u5206\u652f\u4e2d\u7684\u590d\u6742\u5339\u914d3. \u7406\u89e3\u4f5c\u7528\u57df&#xff1a;\u5b83\u4e0d\u4ec5\u4ec5\u662f\u201c\u5c40\u90e8\u53d8\u91cf\u201d3.1 \u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u65b0\u4f5c\u7528\u57df3.2 \u5faa\u73af\u4e0e if \u5757\u7684\u4f5c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/60052.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-14T14:05:22+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60052.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/60052.html\",\"name\":\"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-14T14:05:22+00:00\",\"dateModified\":\"2026-01-14T14:05:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/60052.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/60052.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60052.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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:\/\/www.wsisp.com\/helps\/60052.html","og_locale":"zh_CN","og_type":"article","og_title":"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u76ee\u5f55Python 3.8 \u65b0\u7279\u6027&#xff1a;\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff08;The Walrus Operator&#xff09;1. \u4ec0\u4e48\u662f\u8d4b\u503c\u8868\u8fbe\u5f0f&#xff1f;\u6253\u7834\u4f20\u7edf\u7684\u201c:\u201d2. \u6838\u5fc3\u5e94\u7528\u573a\u666f&#xff1a;\u8ba9\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u66f4\u9ad8\u65482.1 while \u5faa\u73af\u4e2d\u7684 read() \u6a21\u5f0f2.2 \u5217\u8868\u63a8\u5bfc\u5f0f\u4e0e walrus \u7684\u5a01\u529b2.3 if \u5206\u652f\u4e2d\u7684\u590d\u6742\u5339\u914d3. \u7406\u89e3\u4f5c\u7528\u57df&#xff1a;\u5b83\u4e0d\u4ec5\u4ec5\u662f\u201c\u5c40\u90e8\u53d8\u91cf\u201d3.1 \u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u65b0\u4f5c\u7528\u57df3.2 \u5faa\u73af\u4e0e if \u5757\u7684\u4f5c","og_url":"https:\/\/www.wsisp.com\/helps\/60052.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-14T14:05:22+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/60052.html","url":"https:\/\/www.wsisp.com\/helps\/60052.html","name":"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-14T14:05:22+00:00","dateModified":"2026-01-14T14:05:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/60052.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/60052.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/60052.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python 3.8 \u65b0\u7279\u6027\uff1a\u6df1\u5165\u7406\u89e3\u5e76\u638c\u63e1\u8d4b\u503c\u8868\u8fbe\u5f0f\uff08The Walrus Operator\uff09"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=60052"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60052\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=60052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=60052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=60052"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=60052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}