{"id":317,"date":"2020-05-02T19:51:28","date_gmt":"2020-05-02T11:51:28","guid":{"rendered":"http:\/\/python.vvipblog.com\/?p=317"},"modified":"2020-05-02T19:51:28","modified_gmt":"2020-05-02T11:51:28","slug":"python%e5%bf%ab%e9%80%9f%e7%bc%96%e7%a8%8b%e5%85%a5%e9%97%a8-%e7%ac%ac4%e7%ab%a0-%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"http:\/\/www.vvipblog.com\/?p=317","title":{"rendered":"Python\u5feb\u901f\u7f16\u7a0b\u5165\u95e8\u2014\u2014\u7b2c4\u7ae0 \u5b57\u7b26\u4e32"},"content":{"rendered":"<p>\u7b2c4\u7ae0 \u5b57\u7b26\u4e32<\/p>\n<p>\u4e00\u3001\u5b57\u7b26\u4e32<br \/>\n\u4e8c\u3001\u5b57\u7b26\u4e32\u7684\u8f93\u51fa\u548c\u8f93\u5165<br \/>\n\u4e09\u3001\u8bbf\u95ee\u5b57\u7b26\u4e32\u4e2d\u7684\u503c<br \/>\n\u56db\u3001\u5b57\u7b26\u4e32\u7684\u5185\u5efa\u51fd\u6570<\/p>\n<p>\u4e00\u3001\u5b57\u7b26\u4e32<\/p>\n<p>\u4ec0\u4e48\u662f\u5b57\u7b26\u4e32\uff1a<br \/>\n1\uff09\u5b57\u7b26\u4e32\u662f\u4e00\u79cd\u8868\u793a\u6587\u672c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\u53ef\u4ee5\u662fASCII\u5b57\u7b26\u3001\u5404\u79cd\u7b26\u53f7\u4ee5\u53ca\u5404\u79cdUnicode\u5b57\u7b26\u3002Python\u4e2d\u7684\u5b57\u7b26\u4e32\u6709\u5982\u4e0b\u4e09\u79cd\u8868\u73b0\u65b9\u5f0f\u3002<br \/>\n\u7b2c\u4e00\u79cd\uff1a\u4f7f\u7528\u5355\u5f15\u53f7\uff1a\u2018a\u2019 \u2018abc\u2019 \u2018123\u2019<br \/>\n\u6ce8\u610f\u3001\u5355\u5f15\u53f7\u8868\u793a\u7684\u5b57\u7b26\u4e32\u4e0d\u80fd\u5305\u542b\u5355\u5f15\u53f7\u3002<br \/>\n\u7b2c\u4e8c\u79cd\uff1a\u4f7f\u7528\u53cc\u5f15\u53f7\uff1a\u201ca\u201d \u201cabc\u201d \u201c123\u201d<br \/>\n\u6ce8\u610f\u3001\u53cc\u5f15\u53f7\u8868\u793a\u7684\u5b57\u7b26\u4e32\u4e0d\u80fd\u5305\u542b\u53cc\u5f15\u53f7\uff0c\u5e76\u4e14\u53ea\u80fd\u4e00\u884c<br \/>\n\u7b2c\u4e09\u79cd\uff1a\u4f7f\u7528\u4e09\u5f15\u53f7\uff08\u4e09\u5bf9\u5355\u5f15\u53f7\u540e\u8005\u4e09\u5bf9\u53cc\u5f15\u53f7\uff09\u5305\u542b\u5b57\u7b26\u3002<br \/>\n\u2018\u2019\u2018\u5b57\u7b26\u4e32\u2019\u2019\u2019 \u201c\u201d&#8221; aaaa&#8221;&#8221;&#8221;&#8221;<br \/>\n\u6ce8\u610f\u3001\u4e09\u4e2a\u5f15\u53f7\u80fd\u5305\u542b\u591a\u884c\u5b57\u7b26\u4e32,\u5728\u8fd9\u4e2a\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u5305\u542b\u6362\u884c\u7b26\u3001\u5236\u8868\u7b26\u3001\u6216\u8005\u5176\u4ed6\u7279\u6b8a\u7b26\u53f7\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u4e09\u5f15\u53f7\u8868\u793a\u7684\u5b57\u7b26\u51fa\u73b0\u5728\u51fd\u6570\u58f0\u660e\u7684\u4e0b\u4e00\u884c\uff0c\u7528\u6765\u6ce8\u91ca\u51fd\u6570\u3002\u4e0eC\u8bed\u8a00\u7684\u5b57\u7b26\u4e32\u4e0d\u540c\u7684\u662f\uff0cPython\u5b57\u7b26\u4e32\u4e0d\u80fd\u88ab\u6539\u53d8\uff0c\u5f53\u7ed9\u4e00\u4e2a\u7d22\u5f15\u4f4d\u7f6e\u8d4b\u503c\u65f6\uff0c\u6bd4\u5982word[0]=\u2018m\u2019\uff0c\u4f1a\u4ea7\u751f\u8bed\u6cd5\u9519\u8bef\u3002<br \/>\n2\uff09\u8f6c\u4e49\u5b57\u7b26\uff0c\u4f7f\u7528print\u8f93\u51fa\u7684\u5b57\u7b26\u4e32\u7684\u65f6\u5019\u6709\u4e9b\u5b57\u7b26\u5df2\u7ecf\u6709\u5b9a\u4e49\u4e86\u4f46\u662f\u8bed\u53e5\u9700\u8981\u8f93\u51fa\u5b83\u4eec\u3002\u4f7f\u7528\u53cd\u659c\u7ebf<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">print(\"let\\'s go\")\n#\u7ed3\u679c\uff1alet's go<\/code><\/pre>\n<p>\u4e8c\u3001\u5b57\u7b26\u4e32\u7684\u8f93\u51fa\u548c\u8f93\u5165<\/p>\n<p>\u5b57\u7b26\u4e32\u8f93\u51fa%\u8868\u793a\u683c\u5f0f\u5316\u8f93\u51fa\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">name = \"\u5c0f\u660e\"\nprint(\"\u5927\u5bb6\u597d\uff0c\u6211\u53eb%s\"%name)\n#\u7528\u9017\u53f7\u9694\u5f00<\/code><\/pre>\n<p>\u5b57\u7b26\u4e32\u8f93\u5165<br \/>\nPython3\u63d0\u4f9b\u4e86input\u51fd\u6570\u4ece\u6807\u51c6\u8f93\u5165\u8bfb\u53d6\u4e00\u884c\u6587\u672c\uff0c\u9ed8\u8ba4\u7684\u6807\u51c6\u8f93\u5165\u662f\u952e\u76d8\u3002\u5b9e\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">#input\u62ec\u53f7\u91cc\u9762\u5185\u5bb9\u4f1a\u5728\u8f93\u5165\u524d\u63d0\u793a\u3002\nuser_name = input(\"\u8bf7\u8f93\u5165\u7528\u6237\u540d\")\nprint(user_name)<\/code><\/pre>\n<p>\u4e09\u3001\u8bbf\u95ee\u5b57\u7b26\u4e32\u4e2d\u7684\u503c<\/p>\n<p>\u5b57\u7b26\u4e32\u7684\u50a8\u5b58\u65b9\u5f0f<br \/>\nPython\u4e2d\u6ca1\u6709\u5b57\u7b26\u7c7b\u578b\uff0c\u5355\u4e2a\u5b57\u7b26\u4e5f\u662f\u4f5c\u4e3a\u5b57\u7b26\u4e32\u4f7f\u7528\u7684\u3002\u5982\u679c\u5e0c\u671b\u8bbf\u95ee\u5b57\u7b26\u4e32\u4e2d\u7684\u67d0\u4e2a\u5b57\u7b26\uff0c\u5219\u9700\u8981\u7528\u4e0b\u6807\u5b9e\u73b0\u3002\u6709\u70b9\u7c7b\u4f3c\u6570\u7ec4\u3002<br \/>\n\u4f7f\u7528\u5207\u7247\u622a\u53d6\u5b57\u7b26\u4e32<br \/>\n\u5207\u7247\u662f\u6307\u5bf9\u64cd\u4f5c\u7684\u5bf9\u8c61\u622a\u53d6\u5176\u4e2d\u4e00\u90e8\u5206\u7684\u64cd\u4f5c\u3002\u5b57\u7b26\u4e32\u3001\u5217\u8868\u3001\u5143\u7ec4\u90fd\u652f\u6301\u5207\u7247\u64cd\u4f5c\u3002\u5207\u7247\u8bed\u6cd5\u683c\u5f0f<br \/>\n[\u8d77\u59cb:\u7ed3\u675f:\u6b65\u957f]<br \/>\n\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5207\u7247\u9009\u53d6\u7684\u533a\u95f4\u5c5e\u4e8e\u5de6\u95ed\u53f3\u5f00\uff0c\u5373\u4ece\u201c\u8d77\u59cb\u201d\u4f4d\u5f00\u59cb\u5230\u201c\u7ed3\u675f\u201d\u4f4d\u524d\u4e00\u4f4d\u7ed3\u675f\uff08\u4e0d\u5305\u542b\u7ed3\u675f\u4f4d\u672c\u8eab\uff09<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">name = \"abcdef\"\nprint(name[0:3])#\u53d6\u4e0b\u68070~2\u7684\u5b57\u7b26\nprint(name[3:5])#\u53d6\u4e0b\u68073\u30014\u7684\u5b57\u7b26\nprint(name[1:-1])#\u53d6\u4e0b\u6807\u4e3a1\u5f00\u59cb\u5230\u5012\u6570\u7b2c2\u4e2a\u5b57\u7b26\nprint(name[2:])#\u53d6\u4e0b\u6807\u5230\u6700\u540e\u7684\u5b57\u7b26\nprint(name[::-2])#\u5012\u5e8f\u4ece\u540e\u5f80\u524d\uff0c\u53d6\u6b65\u957f\u4e3a2\u7684\u5b57\u7b26\n#abc\n#de\n#bcde\n#cdef\n#fdb<\/code><\/pre>\n<p>\u56db\u3001\u5b57\u7b26\u4e32\u7684\u5185\u5efa\u51fd\u6570<\/p>\n<p>\u5b57\u7b26\u4e32\u4f5c\u4e3a\u6700\u5e38\u7528\u7684\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5b83\u63d0\u4f9b\u4e86\u5f88\u591a\u5185\u5efa\u51fd\u6570\u3002<br \/>\n3. find\u51fd\u6570\uff1a\u7528\u4e8e\u68c0\u6d4b\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32sub\uff0c\u5982\u679c\u6307\u5b9astart\uff08\u5f00\u59cb\uff09\u548cend\uff08\u7ed3\u675f\uff09\u8303\u56f4\uff0c\u5219\u68c0\u67e5\u662f\u5426\u5305\u542b\u5728\u6307\u5b9a\u8303\u56f4\u5185\u3002\u5982\u679c\u5305\u542b\u5b50\u5b57\u7b26\u4e32\u5219\u8fd4\u56de\u5f00\u59cb\u7684\u7d22\u5f15\u503c\uff0c\u5426\u5219\u8fd4\u56de-1.<br \/>\n\u8bed\u6cd5\u683c\u5f0f\uff1astr.find(sub[,start[,end]])<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09sub\uff1a\u6307\u5b9a\u68c0\u7d22\u7684\u5b57\u7b26\u4e32<br \/>\n\uff082\uff09start\uff1a\u5f00\u59cb\u7d22\u5f15\uff0c\u9ed8\u8ba4\u4e3a0\u3002<br \/>\n\uff083\uff09end\uff1a\u7ed3\u675f\u7d22\u5f15\uff0c\u9ed8\u8ba4\u4e3a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = 'hello world itheima and itheimaAPP'\nindex = string_example.find(\"itheima\")\nprint(index)\n#\u7ed3\u679c\uff1a12<\/code><\/pre>\n<p>index\u51fd\u6570\uff1a\u662f\u68c0\u6d4b\u5b57\u7b26\u4e32\u4e2d\u662f\u5426\u5305\u542b\u5b50\u5b57\u7b26\u4e32sub\uff0c\u5982\u679c\u6307\u5b9astart\uff08\u5f00\u59cb\uff09\u548cend\uff08\u7ed3\u675f\uff09\u8303\u56f4\uff0c\u5219\u68c0\u67e5\u662f\u5426\u5305\u542b\u5728\u6307\u5b9a\u8303\u56f4\u5185\u3002\u5982\u679c\u5305\u542b\u5b50\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u5b50\u5b57\u7b26\u4e32\u5f00\u59cb\u7684\u7d22\u5f15\u503c\uff0c\u5426\u5219\u629b\u51fa\u5f02\u5e38\u3002<br \/>\n\u8bed\u6cd5\u683c\u5f0f\uff1astr.index(sub[,start[,end]])<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09sub\uff1a\u6307\u5b9a\u68c0\u7d22\u7684\u5b57\u7b26\u4e32<br \/>\n\uff082\uff09start\uff1a\u5f00\u59cb\u7d22\u5f15\uff0c\u9ed8\u8ba4\u4e3a0\u3002<br \/>\n\uff083\uff09end\uff1a\u7ed3\u675f\u7d22\u5f15\uff0c\u9ed8\u8ba4\u4e3a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = 'hello world itheima and itheimaAPP'\nindex = string_example.index(\"itheima\",0,10)\nprint(index)\n#\u7ed3\u679c\uff1aTraceback (most recent call last):\n# File \"D:\\\u4ee3\u7801\\python\\\u6848\u4f8b.py\", line 2, in &lt;module&gt;\n# index = string_example.index(\"itheima\",0,10)\n#ValueError: substring not found<\/code><\/pre>\n<p>count\u51fd\u6570\uff1a\u7528\u4e8e\u7edf\u8ba1\u5b57\u7b26\u4e32\u91cc\u67d0\u4e2a\u5b57\u7b26\u51fa\u73b0\u7684\u6b21\u6570\u3002\u53ef\u9009\u53c2\u6570\u4e3a\u5728\u5b57\u7b26\u4e32\u641c\u7d22\u7684\u5f00\u59cb\u4e0e\u7ed3\u675f\u4f4d\u7f6e\uff0c\u8be5\u51fd\u6570\u8fd4\u56de\u5b50\u5b57\u7b26\u4e32\u5728\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\u3002<br \/>\n\u8bed\u6cd5\u683c\u5f0f\uff1astr.count(sub[,start[,end]])<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09sub\uff1a\u6307\u5b9a\u68c0\u7d22\u7684\u5b57\u7b26\u4e32<br \/>\n\uff082\uff09start\uff1a\u5b57\u7b26\u4e32\u5f00\u59cb\u641c\u7d22\u7684\u4f4d\u7f6e\u3002\u9ed8\u8ba4\u4e3a\u7b2c\u4e00\u4e2a\u5b57\u7b26\uff0c\u8be5\u5b57\u7b26\u7d22\u5f15\u503c\u4e3a0\u3002<br \/>\n\uff083\uff09end\uff1a\u5b57\u7b26\u4e32\u4e2d\u7ed3\u675f\u7d22\u5f15\u7684\u4f4d\u7f6e\uff0c\u9ed8\u8ba4\u4e3a\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = 'hello world itheima and itheimaAPP'\nresult = string_example.count(\"itheima\")\nprint(result)\n#\u7ed3\u679c: 2<\/code><\/pre>\n<p>replace\u51fd\u6570\u628a\u5b57\u7b26\u4e32\u4e2d\u7684old(\u65e7\u5b57\u7b26\u4e32)\u66ff\u6362\u6210new\uff08\u65b0\u5b57\u7b26\u4e32\uff09\uff0c\u8be5\u51fd\u6570\u8fd4\u56de\u7684\u662f\u5b57\u7b26\u4e32\u4e2d\u7684old\uff08\u65e7\u5b57\u7b26\u4e32\uff09\u66ff\u6362\u6210new\uff08\u65b0\u5b57\u7b26\u4e32\uff09\u540e\u751f\u6210\u7684\u65b0\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6307\u5b9a\u7b2c3\u4e2a\u53c2\u6570count\uff0c\u5219\u66ff\u6362\u6b21\u6570\u4e0d\u8d85\u8fc7count\u6b21\u3002<br \/>\n\u8bed\u6cd5\u683c\u5f0f\uff1astr.replace(old,new[,count])<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09old\uff1a\u5c06\u88ab\u66ff\u6362\u7684\u5b57\u7b26\u4e32\u3002<br \/>\n\uff082\uff09new\uff1a\u65b0\u5b57\u7b26\u4e32\uff0c\u7528\u4e8e\u66ff\u6362old\u5b50\u5b57\u7b26\u4e32\u3002<br \/>\n\uff083\uff09end\uff1a\u53ef\u9009\u53c2\u6570\uff0c\u66ff\u6362\u4e0d\u8d85\u8fc7count\u6b21\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">old_string = 'hello world itheima and itheimaAPP'\nnew_string = old_string.replace(\"itheima\",\"ITHEIMA\",1)\nprint(new_string)\n#\u7ed3\u679c\u662f\uff1ahello world ITHEIMA and itheimaAPP<\/code><\/pre>\n<p>split\u51fd\u6570\u901a\u8fc7\u6307\u5b9a\u5206\u9694\u7b26\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u5207\u7247\uff0c\u5982\u679c\u53c2\u6570maxsplit\u6709\u6307\u5b9a\u503c\uff0c\u5219\u4ec5\u5206\u5272maxsplit\u4e2a\u5b50\u5b57\u7b26\u4e32\uff0c\u8be5\u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f\u5206\u5272\u540e\u7684\u5b57\u7b26\u4e32\u5217\u8868\u3002<br \/>\n\u8bed\u6cd5\u683c\u5f0f\uff1astr.split(sep=None,maxsplit=-1)<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09sep:\u5206\u9694\u7b26\uff0c\u9ed8\u8ba4\u4e3a\u6240\u6709\u7a7a\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u683c\u3001\u6362\u884c\uff08\\n\uff09,\u5236\u8868\u7b26\uff08\\t\uff09\u7b49\u3002<br \/>\n\uff082\uff09maxsplit\uff1a\u5206\u5272\u6b21\u6570\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = \"this is string example ... wor\"\nprint(string_example.split())\nprint(string_example.split(\"i\",1))\nprint(string_example.split(\"w\"))\n#\u7ed3\u679c\uff1a\n#['this', 'is', 'string', 'example', '...', 'wor']\n#['th', 's is string example ... wor']\n#['this is string example ... ', 'or']<\/code><\/pre>\n<p>capitalize\u51fd\u6570\u7528\u4e8e\u5c06\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bcd\u53d8\u6210\u5927\u5199\uff0c\u5176\u4ed6\u5b57\u7b26\u53d8\u6210\u5c0f\u5199\uff0c\u8be5\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u9996\u5b57\u6bcd\u5927\u5199\u7684\u5b57\u7b26\u4e32\u3002<br \/>\n\u8bed\u6cd5\u683c\u5f0f\uff1astr.capitalize()<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">old_string = 'hello word itheima and itheimaApp'\nnew_string = old_string.capitalize()\nprint(new_string)\n#\u7ed3\u679c\uff1a Hello word itheima and itheimaapp<\/code><\/pre>\n<p>title\u51fd\u6570\u8fd4\u56de\u201c\u6807\u9898\u5316\u201d\u7684\u5b57\u7b26\u4e32\uff0c\u4e5f\u5c31\u662f\u8bf4\u6240\u6709\u7684\u5355\u8bcd\u90fd\u662f\u4ee5\u5927\u5199\u5f00\u59cb\uff0c\u5176\u4f59\u5b57\u6bcd\u5747\u4e3a\u5c0f\u5199\u3002<br \/>\n\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b<br \/>\nstr.title()<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">old_string = 'hello word itheima and itheimaApp'\nnew_string = old_string.title()\nprint(new_string)\n#\u7ed3\u679c Hello Word Itheima And Itheimaapp<\/code><\/pre>\n<p>startswtih\u51fd\u6570\u7528\u4e8e\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u662f\u4ee5\u6307\u5b9a\u5b57\u7b26\u4e32\u5f00\u5934\uff0c\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse\u3002\u82e5\u6307\u5b9a\u4e86start\u548cend\u53c2\u6570\u7684\u503c\uff0c\u5219\u4f1a\u5728\u6307\u5b9a\u7684\u8303\u56f4\u5185\u68c0\u67e5\u3002\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b<br \/>\nstr.startswith(prefix[,start[,end]])<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09prefix\uff1a\u68c0\u6d4b\u7684\u5b57\u7b26\u4e32\u3002<br \/>\n\uff082\uff09start\uff1a\u53ef\u9009\u53c2\u6570\uff0c\u7528\u4e8e\u8bbe\u7f6e\u5b57\u7b26\u4e32\u68c0\u6d4b\u7684\u8d77\u59cb\u4f4d\u7f6e\u3002<br \/>\n\uff083\uff09end\uff1a\u53ef\u9009\u53c2\u6570\uff0c\u7528\u4e8e\u8bbe\u7f6e\u5b57\u7b26\u4e32\u68c0\u6d4b\u7684\u7ed3\u675f\u4f4d\u7f6e\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">old_string = 'hello word itheima and itheimaApp'\nnew_string = old_string.startswith(\"hello\")\nprint(new_string)\n#\u7ed3\u679c\uff1aTure<\/code><\/pre>\n<p>endswith\u51fd\u6570\u7528\u4e8e\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4ee5\u6307\u5b9a\u540e\u7f00\u7ed3\u5c3e\uff0c\u5982\u679c\u4ee5\u6307\u5b9a\u540e\u7f00\u7ed3\u5c3e\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse\u3002\u53ef\u9009\u53c2\u6570\u201cstart\u201d\u4e0e\u201cend\u201d\u4e3a\u68c0\u7d22\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u4e0e\u7ed3\u675f\u4f4d\u7f6e\u3002<br \/>\nstr.endswith(suffix[,start[,end]])<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09suffix\uff1a\u8be5\u53c2\u6570\u53ef\u4ee5\u662f\u4e00\u4e2a\u5b57\u7b26\u6216\u8005\u4e00\u4e2a\u5143\u7d20\u3002<br \/>\n\uff082\uff09start\uff1a\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u4f4d\u7f6e\u3002<br \/>\n\uff083\uff09end\uff1a\u5b57\u7b26\u4e32\u4e2d\u7684\u7ed3\u675f\u4f4d\u7f6e\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = 'hello word itheima and itheimaApp'\nnew_string_one = string_example.endswith(\"app\")\nnew_string_two = string_example.endswith(\"App\")\nprint(new_string_one)\nprint(new_string_two)\n#\u7ed3\u679c\uff1a\n#False\n#True<\/code><\/pre>\n<p>upper\u51fd\u6570\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u4e3a\u5927\u5199\u5b57\u6bcd\uff0c\u8fd4\u56de\u5c0f\u5199\u5b57\u6bcd\u8f6c\u5927\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\u3002\u8bed\u6cd5\u683c\u5f0f\uff1a<br \/>\nstr.upper()<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">old_string = 'hello word itheima and itheimaApp'\nnew_string = old_string.upper()\nprint(new_string)\n#\u7ed3\u679c\uff1aHELLO WORD ITHEIMA AND ITHEIMAAPP<\/code><\/pre>\n<p>ljust\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u539f\u5b57\u7b26\u4e32\u5de6\u5bf9\u9f50\uff0c\u5e76\u4f7f\u7528\u7a7a\u683c\u586b\u5145\u81f3\u957f\u5ea6\u7684\u65b0\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6307\u5b9a\u957f\u5ea6\u5c0f\u4e8e\u539f\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff0c\u5219\u8fd4\u56de\u539f\u5b57\u7b26\u4e32\u3002<br \/>\nstr.ljust[width[,fillchar[]]<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09width\uff1a\u6307\u5b9a\u5b57\u7b26\u4e32\u957f\u5ea6\u3002<br \/>\n\uff082\uff09fillchar\uff1a\u586b\u5145\u5b57\u7b26\uff0c\u9ed8\u8ba4\u4e3a\u7a7a\u683c\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = \"Runoob example ...wor!!!\"\nprint(string_example.ljust(50,'*'))\n#\u7ed3\u679c\uff1aRunoob example ...wor!!!**************************<\/code><\/pre>\n<p>rjust\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u539f\u5b57\u7b26\u4e32\u53f3\u5bf9\u9f50\uff0c\u5e76\u4f7f\u7528\u7a7a\u683c\u586b\u5145\u81f3\u957f\u5ea6\u4e3awidth\u7684\u65b0\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6307\u5b9a\u7684\u957f\u5ea6\u5c0f\u4e8e\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff0c\u5219\u8fd4\u56de\u539f\u5b57\u7b26\u4e32\u3002<br \/>\nstr.rjust[width[,fillchar[]]<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09width\uff1a\u6307\u5b9a\u5b57\u7b26\u4e32\u957f\u5ea6\u3002<br \/>\n\uff082\uff09fillchar\uff1a\u586b\u5145\u5b57\u7b26\uff0c\u9ed8\u8ba4\u4e3a\u7a7a\u683c\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = \"Runoob example ...wor!!!\"\nprint(string_example.rjust(50,'*'))<\/code><\/pre>\n<p>center\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u5bbd\u5ea6\u4e3awidth\uff0c\u5b57\u7b26\u4e32\u5c45\u4e2d\uff0c\u4ee5fillchar\uff08\u9ed8\u8ba4\u4e3a\u7a7a\u683c\uff09\u586b\u5145\u5de6\u53f3\u4e24\u8fb9\u7684\u5b57\u7b26\u4e32\u3002<br \/>\nstr.center[width[,fillchar[]]<br \/>\n\u53c2\u6570\u542b\u4e49\u5982\u4e0b\u3002<br \/>\n\uff081\uff09width\uff1a\u6307\u5b9a\u5b57\u7b26\u4e32\u957f\u5ea6\u3002<br \/>\n\uff082\uff09fillchar\uff1a\u586b\u5145\u5b57\u7b26\uff0c\u9ed8\u8ba4\u4e3a\u7a7a\u683c\u3002<\/p>\n<pre class=\"line-numbers\"><code class=\"language-markup\">string_example = \"Runoob example ...wor!!!\"\nprint(string_example.center(50,'*'))\n\u7ed3\u679c\uff1a*************Runoob example ...wor!!!*************<\/code><\/pre>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br \/>\n\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3aCSDN\u535a\u4e3b\u300c\u83e0\u841d\u5927\u5e08\u300d\u7684\u539f\u521b\u6587\u7ae0\uff0c\u9075\u5faaCC 4.0 BY-SA\u7248\u6743\u534f\u8bae\uff0c\u8f6c\u8f7d\u8bf7\u9644\u4e0a\u539f\u6587\u51fa\u5904\u94fe\u63a5\u53ca\u672c\u58f0\u660e\u3002<br \/>\n\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/blog.csdn.net\/xhb29\/article\/details\/85248728<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c4\u7ae0 \u5b57\u7b26\u4e32 \u4e00\u3001\u5b57\u7b26\u4e32 \u4e8c\u3001\u5b57\u7b26\u4e32\u7684\u8f93\u51fa\u548c\u8f93\u5165 \u4e09\u3001\u8bbf\u95ee\u5b57\u7b26\u4e32\u4e2d\u7684\u503c \u56db\u3001\u5b57\u7b26\u4e32\u7684\u5185\u5efa\u51fd\u6570 \u4e00\u3001\u5b57\u7b26\u4e32 \u4ec0&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[24],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-py0","tag-python"],"_links":{"self":[{"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=317"}],"version-history":[{"count":0,"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.vvipblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}