{"id":495,"date":"2017-02-08T23:35:36","date_gmt":"2017-02-08T15:35:36","guid":{"rendered":"http:\/\/192.168.1.20\/?p=495"},"modified":"2017-10-23T11:57:24","modified_gmt":"2017-10-23T03:57:24","slug":"python{d4daabd1ba368d9860c36387ddb72bbda14f8f9559d69d60a952800885260c03}e7{d4daabd1ba368d9860c36387ddb72bbda14f8f9559d69d60a952800885260c03}bc{47dd41ec6bdcbd9a214c783a3735392b82ea6d1d918378c5a53e06407","status":"publish","type":"post","link":"http:\/\/alextop.top\/?p=495","title":{"rendered":"python\u7f16\u7a0b\u95ee\u9898 while invalid syntax"},"content":{"rendered":"<p style=\"background: white\"><span style=\"color:#333333; font-family:\u5fae\u8f6f\u96c5\u9ed1\"><a name=\"here\"\/>\u60a8\u597d\uff0c1\uff09\u5fd8\u8bb0\u5728 if , elif , else , for , while , class ,def \u58f0\u660e\u672b\u5c3e\u6dfb\u52a0 \uff1a\uff08\u5bfc\u81f4 &#8220;SyntaxError \uff1ainvalid syntax&#8221;\uff09 \u8be5\u9519\u8bef\u5c06\u53d1\u751f\u5728\u7c7b\u4f3c\u5982\u4e0b\u4ee3\u7801\u4e2d\uff1a if spam == 42 print(&#8216;Hello!&#8217;) 2)\u4f7f\u7528 = \u800c\u4e0d\u662f ==\uff08\u5bfc\u81f4&#8221;SyntaxError: invalid syntax&#8221;\uff09 = \u662f\u8d4b\u503c\u64cd\u4f5c\u7b26\u800c == \u662f\u7b49\u4e8e\u6bd4\u8f83\u64cd\u4f5c\u3002\u8be5\u9519\u8bef\u53d1\u751f\u5728\u5982\u4e0b\u4ee3\u7801\u4e2d\uff1a if spam = 42: print(&#8216;Hello!&#8217;) 3\uff09\u9519\u8bef\u7684\u4f7f\u7528\u7f29\u8fdb\u91cf\u3002\uff08\u5bfc\u81f4&#8221;IndentationError\uff1aunexpected indent&#8221;\u3001&#8221;IndentationError\uff1aunindent does not match any outer indetation level&#8221;\u4ee5\u53ca&#8221;IndentationError\uff1aexpected an indented block&#8221;\uff09 \u8bb0\u4f4f\u7f29\u8fdb\u589e\u52a0\u53ea\u7528\u5728\u4ee5\uff1a\u7ed3\u675f\u7684\u8bed\u53e5\u4e4b\u540e\uff0c\u800c\u4e4b\u540e\u5fc5\u987b\u6062\u590d\u5230\u4e4b\u524d\u7684\u7f29\u8fdb\u683c\u5f0f\u3002\u8be5\u9519\u8bef\u53d1\u751f\u5728\u5982\u4e0b\u4ee3\u7801\u4e2d\uff1a print(&#8216;Hello!&#8217;) print(&#8216;Howdy!&#8217;) \u6216\u8005\uff1a if spam == 42: print(&#8216;Hello!&#8217;) print(&#8216;Howdy!&#8217;) \u6216\u8005\uff1a if spam == 42: print(&#8216;Hello!&#8217;) 4\uff09\u5728 for \u5faa\u73af\u8bed\u53e5\u4e2d\u5fd8\u8bb0\u8c03\u7528 len() (\u5bfc\u81f4&#8221;TypeError: &#8216;list&#8217; object cannot be interpreted as an integer&#8221;) \u901a\u5e38\u4f60\u60f3\u8981\u901a\u8fc7\u7d22\u5f15\u6765\u8fed\u4ee3\u4e00\u4e2alist\u6216\u8005string\u7684\u5143\u7d20\uff0c\u8fd9\u9700\u8981\u8c03\u7528 range() \u51fd\u6570\u3002\u8981\u8bb0\u5f97\u8fd4\u56delen \u503c\u800c\u4e0d\u662f\u8fd4\u56de\u8fd9\u4e2a&#8230;1\uff09\u5fd8\u8bb0\u5728 if , elif , else , for , while , class ,def \u58f0\u660e\u672b\u5c3e\u6dfb\u52a0 \uff1a\uff08\u5bfc\u81f4 &#8220;SyntaxError \uff1ainvalid syntax&#8221;\uff09<br \/>\u8be5\u9519\u8bef\u5c06\u53d1\u751f\u5728\u7c7b\u4f3c\u5982\u4e0b\u4ee3\u7801\u4e2d\uff1a<br \/>if spam == 42<br \/>print(&#8216;Hello!&#8217;)<\/p>\n<p>2)\u4f7f\u7528 = \u800c\u4e0d\u662f ==\uff08\u5bfc\u81f4&#8221;SyntaxError: invalid syntax&#8221;\uff09<br \/>= \u662f\u8d4b\u503c\u64cd\u4f5c\u7b26\u800c == \u662f\u7b49\u4e8e\u6bd4\u8f83\u64cd\u4f5c\u3002\u8be5\u9519\u8bef\u53d1\u751f\u5728\u5982\u4e0b\u4ee3\u7801\u4e2d\uff1a<br \/>if spam = 42:<\/p>\n<p>print(&#8216;Hello!&#8217;)<br \/>3\uff09\u9519\u8bef\u7684\u4f7f\u7528\u7f29\u8fdb\u91cf\u3002\uff08\u5bfc\u81f4&#8221;IndentationError\uff1aunexpected indent&#8221;\u3001&#8221;IndentationError\uff1aunindent does not match any outer indetation level&#8221;\u4ee5\u53ca&#8221;IndentationError\uff1aexpected an indented block&#8221;\uff09<br \/>\u8bb0\u4f4f\u7f29\u8fdb\u589e\u52a0\u53ea\u7528\u5728\u4ee5\uff1a\u7ed3\u675f\u7684\u8bed\u53e5\u4e4b\u540e\uff0c\u800c\u4e4b\u540e\u5fc5\u987b\u6062\u590d\u5230\u4e4b\u524d\u7684\u7f29\u8fdb\u683c\u5f0f\u3002\u8be5\u9519\u8bef\u53d1\u751f\u5728\u5982\u4e0b\u4ee3\u7801\u4e2d\uff1a<br \/>print(&#8216;Hello!&#8217;)<br \/>print(&#8216;Howdy!&#8217;)<br \/>\u6216\u8005\uff1a<br \/>if spam == 42:<br \/>print(&#8216;Hello!&#8217;)<br \/>print(&#8216;Howdy!&#8217;)<br \/>\u6216\u8005\uff1a<br \/>if spam == 42:<br \/>print(&#8216;Hello!&#8217;)<br \/>4\uff09\u5728 for \u5faa\u73af\u8bed\u53e5\u4e2d\u5fd8\u8bb0\u8c03\u7528 len() (\u5bfc\u81f4&#8221;TypeError: &#8216;list&#8217; object cannot be interpreted as an integer&#8221;)<br \/>\u901a\u5e38\u4f60\u60f3\u8981\u901a\u8fc7\u7d22\u5f15\u6765\u8fed\u4ee3\u4e00\u4e2alist\u6216\u8005string\u7684\u5143\u7d20\uff0c\u8fd9\u9700\u8981\u8c03\u7528 range() \u51fd\u6570\u3002\u8981\u8bb0\u5f97\u8fd4\u56delen \u503c\u800c\u4e0d\u662f\u8fd4\u56de\u8fd9\u4e2a\u5217\u8868\u3002<br \/>\u8be5\u9519\u8bef\u53d1\u751f\u5728\u5982\u4e0b\u4ee3\u7801\u4e2d\uff1a<br \/>spam = [&#8216;cat&#8217;, &#8216;dog&#8217;, &#8216;mouse&#8217;]<br \/>for i in range(spam):<br \/>print(spam[i])<br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u60a8\u597d\uff0c1\uff09\u5fd8\u8bb0\u5728 if , e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,10],"tags":[],"class_list":["post-495","post","type-post","status-publish","format-standard","hentry","category-python","category-jishu"],"_links":{"self":[{"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/posts\/495"}],"collection":[{"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=495"}],"version-history":[{"count":1,"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/posts\/495\/revisions"}],"predecessor-version":[{"id":1007,"href":"http:\/\/alextop.top\/index.php?rest_route=\/wp\/v2\/posts\/495\/revisions\/1007"}],"wp:attachment":[{"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=495"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/alextop.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}