{"id":128,"date":"2016-01-13T19:45:34","date_gmt":"2016-01-13T19:45:34","guid":{"rendered":"http:\/\/yellingstone.info\/?p=128"},"modified":"2016-04-13T00:19:34","modified_gmt":"2016-04-12T22:19:34","slug":"%e6%a0%b8%e5%bf%83%e8%af%ad%e8%a8%80%e5%ad%a6%e6%97%a0%e7%bc%96%e7%a8%8b%e5%9f%ba%e7%a1%80%e5%85%a5%e9%97%a8python%ef%bc%88%e7%ac%ac%e4%ba%8c%e7%ab%a0%ef%bc%89","status":"publish","type":"post","link":"http:\/\/yellingstone.info\/?p=128","title":{"rendered":"\u6838\u5fc3\u8bed\u8a00\u5b66\u65e0\u7f16\u7a0b\u57fa\u7840\u5165\u95e8Python\uff08\u7b2c\u4e8c\u7ae0\uff09"},"content":{"rendered":"<p>\u5efa\u8bae\u5148\u770b\u5b8c\u524d\u9762\u7684\u7ae0\u8282\uff0c\u524d\u9762\u7ae0\u8282\u5185\u5bb9\uff1a<!--more--><\/p>\n<ol>\n<li><a href=\"http:\/\/yellingstone.info\/?p=64\">\u548cPython\u597d\u597d\u8c08\u4e00\u8c08\uff08print\uff09<\/a><\/li>\n<li><a href=\"http:\/\/yellingstone.info\/?p=64\">Python\u4f60\u5e2e\u6211\u7701\u7701\u5fc3\u554a\uff08=\uff09<\/a><\/li>\n<\/ol>\n<hr>\n<p>3 \u628a\u6587\u5b57\u626d\u4e00\u626d\uff08\u5173\u4e8estring\u7684\u547d\u4ee4\uff09<\/p>\n<p>\u77e5\u9053\u6570\u5b57\uff08number\uff09\u548c\u5b57\u4e32\uff08string\uff09\u6709\u533a\u522b\uff0c\u597d\u50cf\u6682\u65f6\u5bf9\u6838\u5fc3\u8bed\u8a00\u5b66\u4e5f\u6ca1\u4ec0\u4e48\u7528\u3002\u7279\u522b\u662f\u6570\u5b57\uff08number\uff09\uff0c\u771f\u662f\u4e00\u70b9\u5375\u7528\u4e5f\u6ca1\u6709\u3002\u548c\u8bed\u8a00\u3001\u6587\u5b57\u6709\u70b9\u5173\u7cfb\u7684\u597d\u50cf\u5c31\u53ea\u6709\u5b57\u4e32\uff08string\uff09\u3002\u60f3\u60f3\u770b\u81ea\u5df1\u4e3a\u4ec0\u4e48\u8981\u5b66Python\uff0c\u6700\u521d\u5927\u6982\u4e5f\u5c31\u662f\u60f3\u628a\u6d77\u91cf\u6587\u5b57\u5927\u5c0f\u5199\u6362\u4e00\u6362\uff0c\u6807\u70b9\u7b26\u53f7\u5220\u4e00\u5220\uff0c\u628a\u4e0d\u9700\u8981\u7684\u51e0\u4e2a\u5b57\u6bcd\u5220\u4e00\u5220\uff0c\u627e\u627e\u4e00\u4e9b\u7ec4\u5408\u5728\u54ea\u91cc\uff0c\u6216\u8005\u63d0\u53d6\u4e2d\u95f4\u51e0\u4e2a\u5b57\u6bcd\u4e4b\u7c7b\u7684\u3002<\/p>\n<p>\u8981\u5b9e\u73b0\u8fd9\u4e9b\u529f\u80fd\uff0c\u6700\u57fa\u672c\u7684\u662f\u5b57\u4e32\u547d\u4ee4\u3002\u5b57\u4e32\u547d\u4ee4\u6570\u91cf\u5f88\u591a\uff0c\u4e0d\u8fc7\u5927\u6982\u7684\u7ed3\u6784\u90fd\u662f<\/p>\n<p><code>\u5b57\u4e32.\u67d0\u547d\u4ee4(\u67d0\u53c2\u6570)<\/code><\/p>\n<p>\uff08\u8fd8\u662f\u60f3\u591a\u4e00\u53e5\u5634\uff0c\u5b57\u4e32\u53ef\u4ee5\u662f\u4e34\u65f6\u7528\u5f15\u53f7\u624b\u5199\u51fa\u6765\u7684\uff08\u52a0&#8221;&#8221;\uff09\uff0c\u4e5f\u53ef\u4ee5\u4e4b\u524d\u5c31\u8d4b\u503c\u8fc7\u7684\u4e00\u4e2a\u53d8\u91cf\uff0c\u6bd4\u5982\u4e0b\u9762\u7684a\uff09<\/p>\n<p>\u4ece\u67e5\u627efind\u8fd9\u4e2a\u547d\u4ee4\u5165\u624b\u5427\uff1a<\/p>\n<p>[code language=&#8221;python&#8221;]<br \/>\n#\u811a\u672c1<br \/>\na=&quot;Python so easy&quot;<br \/>\na.find(&quot;so&quot;)<br \/>\n# =&gt;<br \/>\n[\/code]<\/p>\n<p>\u8fd9\u6bb5\u811a\u672c\u7ffb\u8bd1\u4e00\u4e0b\u5c31\u662f\u8bf4\uff0c\u5728a\u8fd9\u4e2a\u5b57\u4e32\u91cc\uff08\u6ce8\uff1a\u8bf7\u628a\u7a7a\u683c\u4e5f\u7406\u89e3\u4e3a\u5b57\u4e32\u91cc\u7684\u4e00\u4e2a\u5b57\u7b26\uff09\u67e5\u627eso\u8fd9\u4e2a\u5b57\u4e32\uff08\u5176\u5b9e\u662f&#8221;so&#8221;\uff09\u3002\u4e0d\u8fc7\u4e0a\u9762\u8fd9\u6bb5\u811a\u672c\u6709\u4e2a\u95ee\u9898\uff0cPython\u53ea\u662f\u81ea\u5df1\u5728\u7cfb\u7edf\u91cc\u9762\u67e5\u4e86\u4e00\u4e0ba\u8fd9\u4e2a\u5b57\u4e32\u91cc\u9762\u6709\u6ca1\u6709&#8221;so&#8221;\uff0c\u4f46\u662f\u3010\u6ca1\u6709\u7ed9\u6211\u4efb\u4f55\u53cd\u9988\u3011\uff0c\u81ea\u5df1\u5728\u5185\u5b58\u91cc\u6396\u7740\u85cf\u7740\u3002\u600e\u4e48\u529e\u5462\uff0c\u5148\u628aa.find(&#8220;so&#8221;)\u7684\u7ed3\u679c\u3010\u627e\u4e2a\u5730\u65b9\u5b58\u4e00\u4e0b\/\uff08\u8d4b\u503c\uff01\uff09\u3011\uff0c\u7136\u540e\u518dprint\u4e00\u4e0b\u5c31\u597d\u3002<\/p>\n<p>[code language=&#8221;python&#8221;]<br \/>\n#\u811a\u672c2\uff1a<br \/>\na=&quot;Python so easy&quot;<br \/>\nb=a.find(&quot;so&quot;)<br \/>\nprint b<br \/>\n# =&gt; 7<br \/>\n[\/code]<\/p>\n<p>\u8fd0\u884c\u4e0a\u9762\u8fd9\u4e2a\u811a\u672c\uff0c\u663e\u793a\u7ed3\u679c\u662f7\uff0c\u610f\u601d\u662fPython\u5728a\u8fd9\u4e2a\u957f\u5b57\u4e32\u7684\u7b2c\u300c7\u300d\u4e2a\u4f4d\u7f6e\uff0c\u7ec8\u4e8e\u627e\u5230\u4e86&#8221;so&#8221;\uff0cPython\u8ba1\u7b97\u7684\u65b9\u5f0f\u548ccommon sense\u6709\u70b9\u4e0d\u4e00\u6837\uff0c\u662f\u6309\u71670123456789\u8fd9\u4e2a\u987a\u5e8f\u6765\u7684\u3002\u6240\u4ee5\u5b83\u6240\u8c13\u7684\u300c7\u300d\u5176\u5b9e\u662f\u7b2c\u516b\u4e2a\u5b57\u7b26\u3002\u987a\u5e26\u4e00\u63d0\uff0c\u5982\u679c\u627e\u4e0d\u5230\uff0c\u56de\u590d\u7684\u7ed3\u679c\u662f-1\uff08\u811a\u672c3\uff09\u3002\u8fd9\u4e2a\u6545\u4e8b\u544a\u8bc9\u6211\u4eec\uff0c\u3010\u5b57\u4e32\u547d\u4ee4\u4e00\u822c\u662f\u5b58\u5728\u5185\u5b58\u91cc\u7684\uff0c\u628a\u7ed3\u679c\u5b58\u5230\u4e00\u4e2a\u53d8\u91cf\u91cc\uff0c\u662f\u4fdd\u5b58\u7ed3\u679c\u7684\u4e00\u4e2a\u65b9\u6cd5\u3002\u3011<\/p>\n<p>[code language=&#8221;python&#8221;]<br \/>\n#\u811a\u672c3\uff1a<br \/>\na=&quot;Python so easy&quot;<br \/>\nb=a.find(&quot;is&quot;)<br \/>\nprint b<br \/>\n# =&gt; -1<br \/>\n[\/code]<\/p>\n<p>\u4e00\u4e9b\u6709\u7528\u7684\u5b57\u4e32\u547d\u4ee4\uff0c\u8981\u88ab\u626d\u6765\u626d\u53bb\u7684\u5b57\u4e32\u5c31\u9ed8\u8ba4\u4e3aa\u4e86\uff08\u6ce8\uff1aa=&#8221;Python so easy&#8221;\uff09\u3002<br \/>\n<code>a.lower()<\/code>\t\t\t\u5168\u90e8\u6539\u6210\u5c0f\u5199\uff08\u8bb0\u5f97\u5b58\u5230\u67d0\u4e2a\u5730\u65b9=\uff0c\u4ee5\u4e0b\u540c\u7406\uff09<br \/>\n<code>a.upper()<\/code>\t\t\t\u5168\u90e8\u6539\u6210\u5927\u5199<br \/>\n<code>a.swapcase()<\/code>\t\t\u5927\u5199\u6539\u5c0f\u5199\uff0c\u5c0f\u5199\u6539\u5927\u5199<br \/>\n<code>a.count(\"y\")<\/code>\t\t\u8ba1\u7b97&#8221;y&#8221;\u51fa\u73b0\u8fc7\u51e0\u6b21<br \/>\n<code>a.strip(\"y\")<\/code>\t\t\u628a\u5f00\u5934\u6216\u7ed3\u5c3e\u7684&#8221;y&#8221;\u5220\u4e86<br \/>\n<code>a.replace(\"P\",\"p\")<\/code>\t\u628a&#8221;P&#8221;\u6362\u6210&#8221;p&#8221;<br \/>\n<code>\",\".join(a)<\/code>\t\t\ta\u5b57\u4e32\u4e2d\u6bcf\u4e00\u4e2a\u5b57\u7b26\u540e\u9762\u52a0\u4e00\u4e2a&#8221;,&#8221;<\/p>\n<p>\u5b57\u4e32\u547d\u4ee4\u662f\u53ef\u4ee5\u8fde\u5199\u7684 a.upper().count(&#8220;p&#8221;) \u5168\u90e8\u6539\u6210\u5927\u5199\u4e4b\u540e\u518d\u8ba1\u7b97&#8221;p&#8221;\u51fa\u73b0\u8fc7\u51e0\u6b21\u3002\u5176\u4ed6\u6709\u7528\u7684\u5b57\u4e32\u547d\u4ee4\u53ef\u4ee5\u5728<a href=\"https:\/\/docs.python.org\/2\/library\/string.html\">\u8fd9\u91cc<\/a>\u627e\u3002<\/p>\n<hr>\n<p>4 \u8ba9\u522b\u4eba\u4e5f\u6765\u53c2\u4e0e\u4e00\u4e0b\uff08raw_input\uff09<\/p>\n<p>\u4f1a\u4e86\u7b80\u5355\u7684\u5b57\u4e32\u547d\u4ee4\u540e\uff0c\u5c31\u53ef\u4ee5\u505a\u5c0f\u7a0b\u5e8f\u4e86-_-<\/p>\n<p>\u5728\u6211\u4eec\u505a\u5c0f\u7a0b\u5e8f\u7684\u9053\u8def\u4e0a\uff0c\u73b0\u5728\u9047\u5230\u6700\u5927\u7684\u963b\u529b\u662f\u6ca1\u529e\u6cd5\u8fdb\u884c\u66f4\u7075\u6d3b\u7684\u4eba\u673a\u4e92\u52a8\uff0c\u7b80\u800c\u8a00\u4e4b\u5c31\u662f\uff0c\u5177\u4f53\u7684\u64cd\u4f5c\u6b65\u9aa4\u5df2\u7ecf\u9650\u5b9a\u6b7b\u4e86\uff0c\u3010\u6211\u7f16\u7684\u811a\u672c\u53ea\u6709\u6211\u8ba4\u8bc6\uff0c\u522b\u4eba\u4e5f\u7528\u4e0d\u4e86\u3011\u3002\u6240\u4ee5\u6211\u4eec\u8981\u5f00\u4e2a\u53e3\uff0c\u5728\u300c\u811a\u672c\u88ab\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u300d\uff0c\u4e5f\u80fd\u627e\u673a\u4f1a\u8ba9\u65b0\u7684\u53d8\u91cf\u88ab\u5199\u8fdb\u6765\u3002\u8fd9\u4e2a\u65f6\u5019\u8981\u7528\u5230raw_input\u8fd9\u4e2a\u547d\u4ee4\uff08\u6ce8\uff1a\u597d\u50cfPython3.x\u91cc\u53ea\u8981\u7528input\u5c31\u884c\u4e86\uff0c\u771f\u662f\u9ad8\u7ea7\uff09\u3002raw_input\u7684\u7528\u6cd5\u662f\uff1a<\/p>\n<p><code>ck=raw_input(\"what are you looking for? \")<\/code><\/p>\n<p>Python\u8bfb\u5230\u8fd9\u884c\u7684\u65f6\u5019\uff0c\u4f1a\u95ee\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\u7684\u4eba\uff0c\u6709\u4ec0\u4e48\u60f3\u88ab\u5199\u5165\u5230ck\u8fd9\u4e2a\u53d8\u91cf\u91cc\u3002\u53ef\u662f\u8981\u5343\u4e07\u6ce8\u610f\uff0c\u73b0\u5728\u88ab\u5199\u5165\u5230ck\u7684\u662f\u4e00\u4e2a\u5b57\u4e32\u3002\u4ec0\u4e48\uff1f\u60f3\u8f93\u5165\u7684\u5176\u5b9e\u662f\u4e00\u4e2a\u6570\u5b57\uff0c\u90a3\u7528int()\u6539\u6210\u6570\u5b57\u5c31\u884c\u4e86\uff08\u6216\u8005float\uff09\u3002<\/p>\n<p><code>ck=int(raw_input(\"what are you looking for? \"))<\/code><\/p>\n<p>\u8fd8\u662f\u5b9e\u6218\u6700\u80fd\u953b\u70bc\u4eba\uff0c\u6765\u505a\u4e00\u4e2a\u3010\u5728\u7279\u5b9a\u6587\u672c\u91cc\u8ba1\u7b97\u67d0\u4e00\u4e2a\u5b57\u4e32\u51fa\u73b0\u7684\u6b21\u6570\u3011\u7684\u5c0f\u7a0b\u5e8f\u5427\u3002<\/p>\n<p>\u4ecePython\u7684\u7ef4\u57fa\u767e\u79d1\u4e0a\u6284\u4e00\u6bb5\u8bdd\u4e0b\u6765\u968f\u4fbf\u627e\u627e\u3002<\/p>\n<p>[code language=&#8221;python&#8221;]<br \/>\n#\u811a\u672c4\uff1a<br \/>\ntext=&quot;Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C++ or Java. The language provides constructs intended to enable clear programs on both a small and large scale.&quot;<br \/>\ntext=text.lower()<br \/>\nck=raw_input(&quot;what are you looking for? &quot;)<br \/>\nb=text.count(ck)<br \/>\nprint b<br \/>\n# =&gt;<br \/>\n[\/code]<\/p>\n<hr>\n<p>\u5c0f\u6284\uff1a\u5b57\u4e32.\u67d0\u547d\u4ee4(\u67d0\u53c2\u6570)\uff0craw_input<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5efa\u8bae\u5148\u770b\u5b8c\u524d\u9762\u7684\u7ae0\u8282\uff0c\u524d\u9762\u7ae0\u8282\u5185\u5bb9\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/yellingstone.info\/index.php?rest_route=\/wp\/v2\/posts\/128"}],"collection":[{"href":"http:\/\/yellingstone.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yellingstone.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yellingstone.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yellingstone.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=128"}],"version-history":[{"count":0,"href":"http:\/\/yellingstone.info\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions"}],"wp:attachment":[{"href":"http:\/\/yellingstone.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yellingstone.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yellingstone.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}