{"id":110564,"date":"2026-09-29T00:24:41","date_gmt":"2026-09-28T16:24:41","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/110564.html"},"modified":"2026-09-29T00:24:41","modified_gmt":"2026-09-28T16:24:41","slug":"python3%e8%bf%ad%e4%bb%a3%e5%99%a8%e6%80%8e%e6%a0%b7%e8%87%aa%e5%ae%9a%e4%b9%89%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/110564.html","title":{"rendered":"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b"},"content":{"rendered":"<h3>1. \u5f15\u8a00<\/h3>\n<p>\u5728 Python \u4e2d&#xff0c;\u8fed\u4ee3\u5668&#xff08;Iterator&#xff09;\u662f\u4e00\u4e2a\u975e\u5e38\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6982\u5ff5\u3002\u65e0\u8bba\u662f for \u5faa\u73af\u904d\u5386\u5217\u8868\u3001\u8bfb\u53d6\u6587\u4ef6\u884c&#xff0c;\u8fd8\u662f\u4f7f\u7528 zip\u3001map \u7b49\u5185\u7f6e\u51fd\u6570&#xff0c;\u80cc\u540e\u90fd\u79bb\u4e0d\u5f00\u8fed\u4ee3\u5668\u3002Python \u5185\u7f6e\u7684\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u5178\u3001\u96c6\u5408\u7b49\u6570\u636e\u7c7b\u578b\u90fd\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;Iterable&#xff09;&#xff0c;\u4f46\u5f88\u591a\u65f6\u5019&#xff0c;\u6211\u4eec\u9700\u8981\u81ea\u5b9a\u4e49\u4e00\u4e2a\u7c7b&#xff0c;\u8ba9\u5b83\u5177\u5907\u8fed\u4ee3\u80fd\u529b&#xff0c;\u4ece\u800c\u66f4\u7075\u6d3b\u5730\u63a7\u5236\u904d\u5386\u903b\u8f91\u3002<\/p>\n<p>\u672c\u6587\u5c06\u501f\u9274\u4e00\u7bc7\u5173\u4e8e Python \u8fed\u4ee3\u5668\u7684\u7ecf\u5178\u6559\u7a0b&#xff0c;\u7ed3\u5408 Python3 \u7684\u8bed\u6cd5\u7279\u6027&#xff0c;\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8fed\u4ee3\u5668\u7c7b&#xff0c;\u5305\u62ec\u6838\u5fc3\u6982\u5ff5\u3001\u5b9e\u73b0\u65b9\u6cd5\u3001\u5e38\u89c1\u5e94\u7528\u573a\u666f\u4ee5\u53ca\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<h3>2. \u8fed\u4ee3\u5668\u4e0e\u53ef\u8fed\u4ee3\u5bf9\u8c61<\/h3>\n<p>\u5728\u52a8\u624b\u5199\u4ee3\u7801\u4e4b\u524d&#xff0c;\u5148\u5398\u6e05\u4e24\u4e2a\u5bb9\u6613\u6df7\u6dc6\u7684\u6982\u5ff5&#xff1a;\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;Iterable&#xff09;\u548c\u8fed\u4ee3\u5668&#xff08;Iterator&#xff09;\u3002<\/p>\n<h4>2.1 \u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;Iterable&#xff09;<\/h4>\n<p>\u53ef\u8fed\u4ee3\u5bf9\u8c61\u662f\u6307\u5b9e\u73b0\u4e86 __iter__() \u65b9\u6cd5\u7684\u5bf9\u8c61&#xff0c;\u5b83\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\u3002\u7b80\u5355\u6765\u8bf4&#xff0c;\u51e1\u662f\u53ef\u4ee5\u7528 for \u5faa\u73af\u904d\u5386\u7684\u5bf9\u8c61&#xff0c;\u90fd\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>lst <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><br \/>\n<span class=\"token keyword\">for<\/span> x <span class=\"token keyword\">in<\/span> lst<span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u91cc\u7684 lst \u5c31\u662f\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002<\/p>\n<h4>2.2 \u8fed\u4ee3\u5668&#xff08;Iterator&#xff09;<\/h4>\n<p>\u8fed\u4ee3\u5668\u662f\u5b9e\u73b0\u4e86 __iter__() \u548c __next__() \u4e24\u4e2a\u65b9\u6cd5\u7684\u5bf9\u8c61\u3002\u5176\u4e2d&#xff1a;<\/p>\n<ul>\n<li>__iter__() \u8fd4\u56de\u8fed\u4ee3\u5668\u81ea\u8eab&#xff1b;<\/li>\n<li>__next__() \u8fd4\u56de\u4e0b\u4e00\u4e2a\u5143\u7d20&#xff0c;\u5f53\u6ca1\u6709\u66f4\u591a\u5143\u7d20\u65f6\u629b\u51fa StopIteration \u5f02\u5e38\u3002<\/li>\n<\/ul>\n<p>\u8fed\u4ee3\u5668\u662f\u4e00\u4e2a\u300c\u4e00\u6b21\u6027\u300d\u5bf9\u8c61&#xff0c;\u904d\u5386\u7ed3\u675f\u540e\u4e0d\u80fd\u518d\u4ece\u5934\u5f00\u59cb\u3002<\/p>\n<h4>2.3 \u4e24\u8005\u7684\u5173\u7cfb<\/h4>\n<p>\u53ef\u4ee5\u7528\u4e00\u53e5\u8bdd\u6982\u62ec&#xff1a;\u53ef\u8fed\u4ee3\u5bf9\u8c61\u901a\u8fc7 iter() \u51fd\u6570\u5f97\u5230\u8fed\u4ee3\u5668&#xff0c;\u8fed\u4ee3\u5668\u901a\u8fc7 next() \u51fd\u6570\u9010\u4e2a\u53d6\u503c\u3002<\/p>\n<p>lst <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><br \/>\nit <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">iter<\/span><span class=\"token punctuation\">(<\/span>lst<span class=\"token punctuation\">)<\/span>      <span class=\"token comment\"># \u83b7\u53d6\u8fed\u4ee3\u5668<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">next<\/span><span class=\"token punctuation\">(<\/span>it<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>     <span class=\"token comment\"># 1<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">next<\/span><span class=\"token punctuation\">(<\/span>it<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>     <span class=\"token comment\"># 2<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">next<\/span><span class=\"token punctuation\">(<\/span>it<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>     <span class=\"token comment\"># 3<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">next<\/span><span class=\"token punctuation\">(<\/span>it<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span>     <span class=\"token comment\"># \u629b\u51fa StopIteration<\/span><\/p>\n<h3>3. \u81ea\u5b9a\u4e49\u8fed\u4ee3\u5668\u7c7b\u7684\u57fa\u672c\u7ed3\u6784<\/h3>\n<p>\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8fed\u4ee3\u5668\u7c7b&#xff0c;\u6838\u5fc3\u5c31\u662f\u5b9e\u73b0 __iter__() \u548c __next__() \u4e24\u4e2a\u65b9\u6cd5\u3002\u4e0b\u9762\u6211\u4eec\u4ece\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u4f8b\u5b50\u5f00\u59cb\u3002<\/p>\n<h4>3.1 \u6700\u7b80\u5355\u7684\u81ea\u5b9a\u4e49\u8fed\u4ee3\u5668<\/h4>\n<p>\u5047\u8bbe\u6211\u4eec\u8981\u5b9e\u73b0\u4e00\u4e2a\u300c\u4ece 0 \u6570\u5230 n-1\u300d\u7684\u8ba1\u6570\u5668&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Counter<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u4e00\u4e2a\u7b80\u5355\u7684\u8ba1\u6570\u5668\u8fed\u4ee3\u5668&#xff0c;\u4ece 0 \u6570\u5230 n-1&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>n <span class=\"token operator\">&#061;<\/span> n<br \/>\n        self<span class=\"token punctuation\">.<\/span>current <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__iter__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> self<\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__next__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> self<span class=\"token punctuation\">.<\/span>current <span class=\"token operator\">&lt;<\/span> self<span class=\"token punctuation\">.<\/span>n<span class=\"token punctuation\">:<\/span><br \/>\n            value <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>current<br \/>\n            self<span class=\"token punctuation\">.<\/span>current <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> value<br \/>\n        <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">raise<\/span> StopIteration<\/p>\n<p>\u4f7f\u7528\u65b9\u5f0f&#xff1a;<\/p>\n<p><span class=\"token keyword\">for<\/span> i <span class=\"token keyword\">in<\/span> Counter<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u8f93\u51fa&#xff1a;0 1 2 3 4<\/span><\/p>\n<h4>3.2 \u4ee3\u7801\u89e3\u6790<\/h4>\n<ul>\n<li>__init__&#xff1a;\u521d\u59cb\u5316\u8fed\u4ee3\u7684\u8d77\u59cb\u72b6\u6001&#xff0c;\u8fd9\u91cc\u7528 self.current \u8bb0\u5f55\u5f53\u524d\u8ba1\u6570\u4f4d\u7f6e\u3002<\/li>\n<li>__iter__&#xff1a;\u8fd4\u56de self&#xff0c;\u8868\u793a\u8fed\u4ee3\u5668\u672c\u8eab\u4e5f\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002<\/li>\n<li>__next__&#xff1a;\u6bcf\u6b21\u8c03\u7528\u8fd4\u56de\u4e0b\u4e00\u4e2a\u503c&#xff1b;\u5f53\u8ba1\u6570\u8fbe\u5230\u4e0a\u9650\u65f6\u629b\u51fa StopIteration&#xff0c;for \u5faa\u73af\u4f1a\u6355\u83b7\u8be5\u5f02\u5e38\u5e76\u81ea\u52a8\u7ed3\u675f\u3002<\/li>\n<\/ul>\n<h3>4. \u8ba9\u81ea\u5b9a\u4e49\u7c7b\u540c\u65f6\u652f\u6301\u8fed\u4ee3\u4e0e\u7d22\u5f15<\/h3>\n<p>\u6709\u65f6\u5019&#xff0c;\u6211\u4eec\u5e0c\u671b\u4e00\u4e2a\u7c7b\u65e2\u80fd\u7528 for \u904d\u5386&#xff0c;\u53c8\u80fd\u50cf\u5217\u8868\u4e00\u6837\u901a\u8fc7\u4e0b\u6807\u8bbf\u95ee\u3002\u8fd9\u65f6\u53ef\u4ee5\u8ba9\u7c7b\u5b9e\u73b0 __iter__ \u548c __getitem__ \u4e24\u4e2a\u65b9\u6cd5\u3002<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">MyList<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>data <span class=\"token operator\">&#061;<\/span> data<\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__getitem__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> index<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> self<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__iter__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token builtin\">iter<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8fd9\u6837&#xff0c;MyList \u65e2\u652f\u6301 for x in obj&#xff0c;\u4e5f\u652f\u6301 obj[0] \u8fd9\u6837\u7684\u4e0b\u6807\u8bbf\u95ee\u3002<\/p>\n<h3>5. \u5b9e\u6218\u6848\u4f8b&#xff1a;\u81ea\u5b9a\u4e49\u4e00\u4e2a\u6590\u6ce2\u90a3\u5951\u8fed\u4ee3\u5668<\/h3>\n<p>\u6590\u6ce2\u90a3\u5951\u6570\u5217\u662f\u5b66\u4e60\u8fed\u4ee3\u5668\u65f6\u6700\u7ecf\u5178\u7684\u4f8b\u5b50\u3002\u7528\u8fed\u4ee3\u5668\u5b9e\u73b0&#xff0c;\u53ef\u4ee5\u505a\u5230\u300c\u6309\u9700\u751f\u6210\u300d&#xff0c;\u907f\u514d\u4e00\u6b21\u6027\u5360\u7528\u5927\u91cf\u5185\u5b58\u3002<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Fibonacci<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6590\u6ce2\u90a3\u5951\u6570\u5217\u8fed\u4ee3\u5668&#xff0c;\u751f\u6210\u524d n \u9879&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>n <span class=\"token operator\">&#061;<\/span> n<br \/>\n        self<span class=\"token punctuation\">.<\/span>count <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>a<span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>b <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__iter__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> self<\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__next__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> self<span class=\"token punctuation\">.<\/span>count <span class=\"token operator\">&lt;<\/span> self<span class=\"token punctuation\">.<\/span>n<span class=\"token punctuation\">:<\/span><br \/>\n            result <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>a<br \/>\n            self<span class=\"token punctuation\">.<\/span>a<span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>b <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>b<span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>a <span class=\"token operator\">&#043;<\/span> self<span class=\"token punctuation\">.<\/span>b<br \/>\n            self<span class=\"token punctuation\">.<\/span>count <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> result<br \/>\n        <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">raise<\/span> StopIteration<\/p>\n<p>\u4f7f\u7528&#xff1a;<\/p>\n<p><span class=\"token keyword\">for<\/span> num <span class=\"token keyword\">in<\/span> Fibonacci<span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>num<span class=\"token punctuation\">,<\/span> end<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034; &#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u8f93\u51fa&#xff1a;0 1 1 2 3 5 8 13 21 34<\/span><\/p>\n<h3>6. \u4f7f\u7528\u751f\u6210\u5668\u7b80\u5316\u8fed\u4ee3\u5668<\/h3>\n<p>Python \u63d0\u4f9b\u4e86\u4e00\u79cd\u66f4\u7b80\u6d01\u7684\u5199\u6cd5\u2014\u2014\u751f\u6210\u5668&#xff08;Generator&#xff09;\u3002\u751f\u6210\u5668\u672c\u8d28\u4e0a\u5c31\u662f\u8fed\u4ee3\u5668&#xff0c;\u4f46\u4e0d\u9700\u8981\u624b\u52a8\u5b9e\u73b0 __iter__ \u548c __next__&#xff0c;\u53ea\u9700\u4f7f\u7528 yield \u5173\u952e\u5b57\u3002<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">fibonacci_gen<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    a<span class=\"token punctuation\">,<\/span> b <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> _ <span class=\"token keyword\">in<\/span> <span class=\"token builtin\">range<\/span><span class=\"token punctuation\">(<\/span>n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">yield<\/span> a<br \/>\n        a<span class=\"token punctuation\">,<\/span> b <span class=\"token operator\">&#061;<\/span> b<span class=\"token punctuation\">,<\/span> a <span class=\"token operator\">&#043;<\/span> b<\/p>\n<p>\u4e0a\u9762\u7684\u751f\u6210\u5668\u51fd\u6570\u4e0e\u524d\u9762\u7684 Fibonacci \u7c7b\u529f\u80fd\u5b8c\u5168\u4e00\u81f4&#xff0c;\u4f46\u4ee3\u7801\u91cf\u5927\u5927\u51cf\u5c11\u3002\u5728\u5927\u591a\u6570\u573a\u666f\u4e0b&#xff0c;\u4f18\u5148\u63a8\u8350\u4f7f\u7528\u751f\u6210\u5668&#xff1b;\u53ea\u6709\u5f53\u9700\u8981\u7ef4\u62a4\u590d\u6742\u72b6\u6001\u6216\u590d\u7528\u8fed\u4ee3\u903b\u8f91\u65f6&#xff0c;\u624d\u8003\u8651\u81ea\u5b9a\u4e49\u8fed\u4ee3\u5668\u7c7b\u3002<\/p>\n<h3>7. \u8fed\u4ee3\u5668\u7684\u5e38\u89c1\u5e94\u7528\u573a\u666f<\/h3>\n<p>\u81ea\u5b9a\u4e49\u8fed\u4ee3\u5668\u7c7b\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u6709\u5f88\u591a\u7528\u9014&#xff0c;\u8fd9\u91cc\u5217\u4e3e\u51e0\u4e2a\u5178\u578b\u573a\u666f&#xff1a;<\/p>\n<h4>7.1 \u5927\u6570\u636e\u6d41\u5f0f\u5904\u7406<\/h4>\n<p>\u5f53\u6570\u636e\u91cf\u5f88\u5927\u3001\u65e0\u6cd5\u4e00\u6b21\u6027\u8f7d\u5165\u5185\u5b58\u65f6&#xff0c;\u53ef\u4ee5\u7528\u8fed\u4ee3\u5668\u9010\u6761\u8bfb\u53d6\u548c\u5904\u7406\u3002\u4f8b\u5982\u81ea\u5b9a\u4e49\u4e00\u4e2a\u9010\u884c\u8bfb\u53d6\u5927\u6587\u4ef6\u7684\u8fed\u4ee3\u5668&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">FileReader<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> filepath<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>filepath <span class=\"token operator\">&#061;<\/span> filepath<\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__iter__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">with<\/span> <span class=\"token builtin\">open<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">.<\/span>filepath<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;r&#034;<\/span><span class=\"token punctuation\">,<\/span> encoding<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;utf-8&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> f<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">for<\/span> line <span class=\"token keyword\">in<\/span> f<span class=\"token punctuation\">:<\/span><br \/>\n                <span class=\"token keyword\">yield<\/span> line<span class=\"token punctuation\">.<\/span>strip<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h4>7.2 \u65e0\u9650\u5e8f\u5217<\/h4>\n<p>\u8fed\u4ee3\u5668\u5929\u7136\u9002\u5408\u8868\u793a\u65e0\u9650\u5e8f\u5217&#xff0c;\u56e0\u4e3a\u5b83\u662f\u60f0\u6027\u6c42\u503c\u7684&#xff0c;\u53ea\u6709\u8c03\u7528 next() \u65f6\u624d\u8ba1\u7b97\u4e0b\u4e00\u4e2a\u503c\u3002<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">NaturalNumbers<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u81ea\u7136\u6570\u8fed\u4ee3\u5668&#xff0c;\u65e0\u9650\u751f\u6210&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__iter__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        n <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n        <span class=\"token keyword\">while<\/span> <span class=\"token boolean\">True<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">yield<\/span> n<br \/>\n            n <span class=\"token operator\">&#043;&#061;<\/span> <span class=\"token number\">1<\/span><\/p>\n<p>\u4f7f\u7528\u65f6\u914d\u5408 itertools.islice \u622a\u53d6\u524d\u82e5\u5e72\u9879&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> itertools <span class=\"token keyword\">import<\/span> islice<\/p>\n<p>nums <span class=\"token operator\">&#061;<\/span> NaturalNumbers<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">for<\/span> x <span class=\"token keyword\">in<\/span> islice<span class=\"token punctuation\">(<\/span>nums<span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># 1 2 3 4 5<\/span><\/p>\n<h4>7.3 \u81ea\u5b9a\u4e49\u904d\u5386\u987a\u5e8f<\/h4>\n<p>\u8fed\u4ee3\u5668\u53ef\u4ee5\u5b8c\u5168\u63a7\u5236\u904d\u5386\u987a\u5e8f&#xff0c;\u4f8b\u5982\u5b9e\u73b0\u4e00\u4e2a\u300c\u5012\u5e8f\u904d\u5386\u300d\u7684\u8fed\u4ee3\u5668&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">ReverseList<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> data<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>data <span class=\"token operator\">&#061;<\/span> data<br \/>\n        self<span class=\"token punctuation\">.<\/span>index <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 operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__iter__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> self<\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__next__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> self<span class=\"token punctuation\">.<\/span>index <span class=\"token operator\">&gt;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            value <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>data<span class=\"token punctuation\">[<\/span>self<span class=\"token punctuation\">.<\/span>index<span class=\"token punctuation\">]<\/span><br \/>\n            self<span class=\"token punctuation\">.<\/span>index <span class=\"token operator\">-&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> value<br \/>\n        <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">raise<\/span> StopIteration<\/p>\n<h3>8. \u6ce8\u610f\u4e8b\u9879\u4e0e\u5e38\u89c1\u5751<\/h3>\n<h4>8.1 \u8fed\u4ee3\u5668\u662f\u4e00\u6b21\u6027\u7684<\/h4>\n<p>\u8fed\u4ee3\u5668\u904d\u5386\u7ed3\u675f\u540e&#xff0c;\u65e0\u6cd5\u91cd\u65b0\u4ece\u5934\u5f00\u59cb\u3002\u5982\u679c\u9700\u8981\u91cd\u590d\u904d\u5386&#xff0c;\u5e94\u91cd\u65b0\u521b\u5efa\u8fed\u4ee3\u5668\u5bf9\u8c61\u3002<\/p>\n<p>it <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">iter<\/span><span class=\"token punctuation\">(<\/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 punctuation\">)<\/span><br \/>\n<span class=\"token builtin\">list<\/span><span class=\"token punctuation\">(<\/span>it<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># [1, 2, 3]<\/span><br \/>\n<span class=\"token builtin\">list<\/span><span class=\"token punctuation\">(<\/span>it<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># []&#xff0c;\u5df2\u7ecf\u8017\u5c3d<\/span><\/p>\n<h4>8.2 __iter__ \u8fd4\u56de self \u7684\u7ea6\u5b9a<\/h4>\n<p>\u5982\u679c\u7c7b\u672c\u8eab\u662f\u8fed\u4ee3\u5668&#xff0c;__iter__ \u5e94\u8fd4\u56de self\u3002\u5982\u679c\u7c7b\u53ea\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;\u5185\u90e8\u6301\u6709\u8fed\u4ee3\u5668&#xff09;&#xff0c;\u5219 __iter__ \u5e94\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u8fed\u4ee3\u5668\u3002<\/p>\n<h4>8.3 \u4e0d\u8981\u5fd8\u8bb0\u629b\u51fa StopIteration<\/h4>\n<p>__next__ \u5728\u5143\u7d20\u8017\u5c3d\u65f6\u5fc5\u987b\u629b\u51fa StopIteration&#xff0c;\u5426\u5219 for \u5faa\u73af\u4f1a\u65e0\u9650\u6267\u884c\u4e0b\u53bb\u3002<\/p>\n<h4>8.4 \u4f18\u5148\u8003\u8651\u751f\u6210\u5668<\/h4>\n<p>\u9664\u975e\u9700\u8981\u590d\u6742\u7684\u7c7b\u72b6\u6001\u7ba1\u7406&#xff0c;\u5426\u5219\u4f18\u5148\u4f7f\u7528\u751f\u6210\u5668\u51fd\u6570&#xff0c;\u4ee3\u7801\u66f4\u7b80\u6d01\u3001\u53ef\u8bfb\u6027\u66f4\u9ad8\u3002<\/p>\n<h3>9. \u603b\u7ed3<\/h3>\n<p>\u672c\u6587\u4ece\u8fed\u4ee3\u5668\u4e0e\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u57fa\u672c\u6982\u5ff5\u51fa\u53d1&#xff0c;\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728 Python3 \u4e2d\u81ea\u5b9a\u4e49\u4e00\u4e2a\u8fed\u4ee3\u5668\u7c7b&#xff0c;\u5305\u62ec\u6838\u5fc3\u65b9\u6cd5 __iter__ \u548c __next__ \u7684\u5b9e\u73b0\u3001\u5b9e\u6218\u6848\u4f8b&#xff08;\u6590\u6ce2\u90a3\u5951\u6570\u5217&#xff09;\u3001\u751f\u6210\u5668\u7684\u7b80\u5316\u5199\u6cd5&#xff0c;\u4ee5\u53ca\u8fed\u4ee3\u5668\u5728\u6d41\u5f0f\u5904\u7406\u3001\u65e0\u9650\u5e8f\u5217\u7b49\u573a\u666f\u4e2d\u7684\u5e94\u7528\u3002<\/p>\n<p>\u638c\u63e1\u81ea\u5b9a\u4e49\u8fed\u4ee3\u5668&#xff0c;\u4e0d\u4ec5\u80fd\u52a0\u6df1\u5bf9 Python \u904d\u5386\u673a\u5236\u7684\u7406\u89e3&#xff0c;\u8fd8\u80fd\u5199\u51fa\u66f4\u9ad8\u6548\u3001\u66f4\u4f18\u96c5\u7684\u4ee3\u7801\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5f15\u8a00<br \/>\n\u5728 Python \u4e2d&#xff0c;\u8fed\u4ee3\u5668&#xff08;Iterator&#xff09;\u662f\u4e00\u4e2a\u975e\u5e38\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6982\u5ff5\u3002\u65e0\u8bba\u662f for \u5faa\u73af\u904d\u5386\u5217\u8868\u3001\u8bfb\u53d6\u6587\u4ef6\u884c&#xff0c;\u8fd8\u662f\u4f7f\u7528 zip\u3001map \u7b49\u5185\u7f6e\u51fd\u6570&#xff0c;\u80cc\u540e\u90fd\u79bb\u4e0d\u5f00\u8fed\u4ee3\u5668\u3002Python \u5185\u7f6e\u7684\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u5178\u3001\u96c6\u5408\u7b49\u6570\u636e\u7c7b\u578b\u90fd\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;Iterable&#xff09;&#xff0c;\u4f46\u5f88\u591a\u65f6\u5019&#xff0c;\u6211\u4eec\u9700\u8981\u81ea\u5b9a\u4e49\u4e00\u4e2a\u7c7b&#xff0c;\u8ba9\u5b83\u5177\u5907\u8fed\u4ee3\u80fd\u529b&amp;#xff0c<\/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":[81,190],"topic":[],"class_list":["post-110564","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b - \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\/110564.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1. \u5f15\u8a00 \u5728 Python \u4e2d&#xff0c;\u8fed\u4ee3\u5668&#xff08;Iterator&#xff09;\u662f\u4e00\u4e2a\u975e\u5e38\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6982\u5ff5\u3002\u65e0\u8bba\u662f for \u5faa\u73af\u904d\u5386\u5217\u8868\u3001\u8bfb\u53d6\u6587\u4ef6\u884c&#xff0c;\u8fd8\u662f\u4f7f\u7528 zip\u3001map \u7b49\u5185\u7f6e\u51fd\u6570&#xff0c;\u80cc\u540e\u90fd\u79bb\u4e0d\u5f00\u8fed\u4ee3\u5668\u3002Python \u5185\u7f6e\u7684\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u5178\u3001\u96c6\u5408\u7b49\u6570\u636e\u7c7b\u578b\u90fd\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;Iterable&#xff09;&#xff0c;\u4f46\u5f88\u591a\u65f6\u5019&#xff0c;\u6211\u4eec\u9700\u8981\u81ea\u5b9a\u4e49\u4e00\u4e2a\u7c7b&#xff0c;\u8ba9\u5b83\u5177\u5907\u8fed\u4ee3\u80fd\u529b&amp;#xff0c\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/110564.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-28T16:24:41+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=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110564.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/110564.html\",\"name\":\"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-09-28T16:24:41+00:00\",\"dateModified\":\"2026-09-28T16:24:41+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/110564.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/110564.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/110564.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b\"}]},{\"@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":"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b - \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\/110564.html","og_locale":"zh_CN","og_type":"article","og_title":"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1. \u5f15\u8a00 \u5728 Python \u4e2d&#xff0c;\u8fed\u4ee3\u5668&#xff08;Iterator&#xff09;\u662f\u4e00\u4e2a\u975e\u5e38\u57fa\u7840\u4e14\u91cd\u8981\u7684\u6982\u5ff5\u3002\u65e0\u8bba\u662f for \u5faa\u73af\u904d\u5386\u5217\u8868\u3001\u8bfb\u53d6\u6587\u4ef6\u884c&#xff0c;\u8fd8\u662f\u4f7f\u7528 zip\u3001map \u7b49\u5185\u7f6e\u51fd\u6570&#xff0c;\u80cc\u540e\u90fd\u79bb\u4e0d\u5f00\u8fed\u4ee3\u5668\u3002Python \u5185\u7f6e\u7684\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u5178\u3001\u96c6\u5408\u7b49\u6570\u636e\u7c7b\u578b\u90fd\u662f\u53ef\u8fed\u4ee3\u5bf9\u8c61&#xff08;Iterable&#xff09;&#xff0c;\u4f46\u5f88\u591a\u65f6\u5019&#xff0c;\u6211\u4eec\u9700\u8981\u81ea\u5b9a\u4e49\u4e00\u4e2a\u7c7b&#xff0c;\u8ba9\u5b83\u5177\u5907\u8fed\u4ee3\u80fd\u529b&amp;#xff0c","og_url":"https:\/\/www.wsisp.com\/helps\/110564.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-09-28T16:24:41+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/110564.html","url":"https:\/\/www.wsisp.com\/helps\/110564.html","name":"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-09-28T16:24:41+00:00","dateModified":"2026-09-28T16:24:41+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/110564.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/110564.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/110564.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"python3\u8fed\u4ee3\u5668\u600e\u6837\u81ea\u5b9a\u4e49\u7c7b"}]},{"@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\/110564","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=110564"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/110564\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=110564"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=110564"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=110564"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=110564"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}