{"id":583,"date":"2025-10-23T15:24:38","date_gmt":"2025-10-23T07:24:38","guid":{"rendered":"http:\/\/www.pyteam.cn\/?p=583"},"modified":"2025-10-23T15:24:38","modified_gmt":"2025-10-23T07:24:38","slug":"python3-%e5%ad%97%e7%ac%a6%e4%b8%b2","status":"publish","type":"post","link":"http:\/\/www.pyteam.cn\/index.php\/2025\/10\/23\/python3-%e5%ad%97%e7%ac%a6%e4%b8%b2\/","title":{"rendered":"Python3\u00a0\u5b57\u7b26\u4e32"},"content":{"rendered":"\n<p>\u5b57\u7b26\u4e32\u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5f15\u53f7(&nbsp;<strong>&#8216;<\/strong>&nbsp;\u6216&nbsp;<strong>&#8220;<\/strong>&nbsp;)\u6765\u521b\u5efa\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<p>\u521b\u5efa\u5b57\u7b26\u4e32\u5f88\u7b80\u5355\uff0c\u53ea\u8981\u4e3a\u53d8\u91cf\u5206\u914d\u4e00\u4e2a\u503c\u5373\u53ef\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<p>var1 = &#8216;Hello World!&#8217; var2 = &#8220;Runoob&#8221;<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python \u8bbf\u95ee\u5b57\u7b26\u4e32\u4e2d\u7684\u503c<\/h2>\n\n\n\n<p>Python \u4e0d\u652f\u6301\u5355\u5b57\u7b26\u7c7b\u578b\uff0c\u5355\u5b57\u7b26\u5728 Python \u4e2d\u4e5f\u662f\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>Python \u8bbf\u95ee\u5b50\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528\u65b9\u62ec\u53f7&nbsp;<strong>[]<\/strong>&nbsp;\u6765\u622a\u53d6\u5b57\u7b26\u4e32\uff0c\u5b57\u7b26\u4e32\u7684\u622a\u53d6\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u53d8\u91cf[\u5934\u4e0b\u6807:\u5c3e\u4e0b\u6807]<\/pre>\n\n\n\n<p>\u7d22\u5f15\u503c\u4ee5&nbsp;<strong>0<\/strong>&nbsp;\u4e3a\u5f00\u59cb\u503c\uff0c<strong>-1<\/strong>&nbsp;\u4e3a\u4ece\u672b\u5c3e\u7684\u5f00\u59cb\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/static.jyshare.com\/wp-content\/uploads\/123456-20200923-1.svg\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.runoob.com\/wp-content\/uploads\/2014\/05\/python-str-runoob.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u5982\u4e0b\u5b9e\u4f8b\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 var1 = &#8216;Hello World!&#8217; var2 = &#8220;Runoob&#8221; print (&#8220;var1[0]: &#8220;, var1[0]) print (&#8220;var2[1:5]: &#8220;, var2[1:5])<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u6267\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var1[0]:  H\nvar2[1:5]:  unoo<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python \u5b57\u7b26\u4e32\u66f4\u65b0<\/h2>\n\n\n\n<p>\u4f60\u53ef\u4ee5\u622a\u53d6\u5b57\u7b26\u4e32\u7684\u4e00\u90e8\u5206\u5e76\u4e0e\u5176\u4ed6\u5b57\u6bb5\u62fc\u63a5\uff0c\u5982\u4e0b\u5b9e\u4f8b\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 var1 = &#8216;Hello World!&#8217; print (&#8220;\u5df2\u66f4\u65b0\u5b57\u7b26\u4e32 : &#8220;, var1[:6] + &#8216;Runoob!&#8217;)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u6267\u884c\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u5df2\u66f4\u65b0\u5b57\u7b26\u4e32 :  Hello Runoob!<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python \u8f6c\u4e49\u5b57\u7b26<\/h2>\n\n\n\n<p>\u5728\u9700\u8981\u5728\u5b57\u7b26\u4e2d\u4f7f\u7528\u7279\u6b8a\u5b57\u7b26\u65f6\uff0cpython \u7528\u53cd\u659c\u6760&nbsp;<strong>\\<\/strong>&nbsp;\u8f6c\u4e49\u5b57\u7b26\u3002\u5982\u4e0b\u8868\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u8f6c\u4e49\u5b57\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><\/thead><tbody><tr><td>\\(\u5728\u884c\u5c3e\u65f6)<\/td><td>\u7eed\u884c\u7b26<\/td><td>&gt;&gt;&gt; print(&#8220;line1 \\ &#8230; line2 \\ &#8230; line3&#8221;) line1 line2 line3 &gt;&gt;&gt;<\/td><\/tr><tr><td>\\\\<\/td><td>\u53cd\u659c\u6760\u7b26\u53f7<\/td><td>&gt;&gt;&gt; print(&#8220;\\\\&#8221;) \\<\/td><\/tr><tr><td>\\&#8217;<\/td><td>\u5355\u5f15\u53f7<\/td><td>&gt;&gt;&gt; print(&#8216;\\&#8221;) &#8216;<\/td><\/tr><tr><td>\\&#8221;<\/td><td>\u53cc\u5f15\u53f7<\/td><td>&gt;&gt;&gt; print(&#8220;\\&#8221;&#8221;) &#8220;<\/td><\/tr><tr><td>\\a<\/td><td>\u54cd\u94c3<\/td><td>&gt;&gt;&gt; print(&#8220;\\a&#8221;)\u6267\u884c\u540e\u7535\u8111\u6709\u54cd\u58f0\u3002<\/td><\/tr><tr><td>\\b<\/td><td>\u9000\u683c(Backspace)<\/td><td>&gt;&gt;&gt; print(&#8220;Hello \\b World!&#8221;) Hello World!<\/td><\/tr><tr><td>\\000<\/td><td>\u7a7a<\/td><td>&gt;&gt;&gt; print(&#8220;\\000&#8221;) &gt;&gt;&gt;<\/td><\/tr><tr><td>\\n<\/td><td>\u6362\u884c<\/td><td>&gt;&gt;&gt; print(&#8220;\\n&#8221;) &gt;&gt;&gt;<\/td><\/tr><tr><td>\\v<\/td><td>\u7eb5\u5411\u5236\u8868\u7b26<\/td><td>&gt;&gt;&gt; print(&#8220;Hello \\v World!&#8221;) Hello World! &gt;&gt;&gt;<\/td><\/tr><tr><td>\\t<\/td><td>\u6a2a\u5411\u5236\u8868\u7b26<\/td><td>&gt;&gt;&gt; print(&#8220;Hello \\t World!&#8221;) Hello &nbsp;&nbsp;&nbsp;&nbsp; World! &gt;&gt;&gt;<\/td><\/tr><tr><td>\\r<\/td><td>\u56de\u8f66\uff0c\u5c06&nbsp;<strong>\\r<\/strong>&nbsp;\u540e\u9762\u7684\u5185\u5bb9\u79fb\u5230\u5b57\u7b26\u4e32\u5f00\u5934\uff0c\u5e76\u9010\u4e00\u66ff\u6362\u5f00\u5934\u90e8\u5206\u7684\u5b57\u7b26\uff0c\u76f4\u81f3\u5c06&nbsp;<strong>\\r<\/strong>&nbsp;\u540e\u9762\u7684\u5185\u5bb9\u5b8c\u5168\u66ff\u6362\u5b8c\u6210\u3002<\/td><td>&gt;&gt;&gt; print(&#8220;Hello\\rWorld!&#8221;) World! &gt;&gt;&gt; print(&#8216;google runoob taobao\\r123456&#8217;) 123456 runoob taobao<\/td><\/tr><tr><td>\\f<\/td><td>\u6362\u9875<\/td><td>&gt;&gt;&gt; print(&#8220;Hello \\f World!&#8221;) Hello World! &gt;&gt;&gt;<\/td><\/tr><tr><td>\\yyy<\/td><td>\u516b\u8fdb\u5236\u6570\uff0cy \u4ee3\u8868 0~7 \u7684\u5b57\u7b26\uff0c\u4f8b\u5982\uff1a\\012 \u4ee3\u8868\u6362\u884c\u3002<\/td><td>&gt;&gt;&gt; print(&#8220;\\110\\145\\154\\154\\157\\40\\127\\157\\162\\154\\144\\41&#8221;) Hello World!<\/td><\/tr><tr><td>\\xyy<\/td><td>\u5341\u516d\u8fdb\u5236\u6570\uff0c\u4ee5 \\x \u5f00\u5934\uff0cy \u4ee3\u8868\u7684\u5b57\u7b26\uff0c\u4f8b\u5982\uff1a\\x0a \u4ee3\u8868\u6362\u884c<\/td><td>&gt;&gt;&gt; print(&#8220;\\x48\\x65\\x6c\\x6c\\x6f\\x20\\x57\\x6f\\x72\\x6c\\x64\\x21&#8221;) Hello World!<\/td><\/tr><tr><td>\\other<\/td><td>\u5176\u5b83\u7684\u5b57\u7b26\u4ee5\u666e\u901a\u683c\u5f0f\u8f93\u51fa<\/td><td>&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u4f7f\u7528&nbsp;<strong>\\r&nbsp;<\/strong>\u5b9e\u73b0\u767e\u5206\u6bd4\u8fdb\u5ea6\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b<\/h2>\n\n\n\n<p><strong>import<\/strong>&nbsp;time<\/p>\n\n\n\n<p><strong>for<\/strong>&nbsp;i&nbsp;<strong>in<\/strong>&nbsp;range(101):&nbsp;# \u6dfb\u52a0\u8fdb\u5ea6\u6761\u56fe\u5f62\u548c\u767e\u5206\u6bd4<br>&nbsp; &nbsp; bar&nbsp;=&nbsp;&#8216;[&#8216;&nbsp;+&nbsp;&#8216;=&#8217;&nbsp;*&nbsp;(i \/\/&nbsp;2)&nbsp;+&nbsp;&#8216; &#8216;&nbsp;*&nbsp;(50&nbsp;&#8211; i \/\/&nbsp;2)&nbsp;+&nbsp;&#8216;]&#8217;<br>&nbsp;<strong>print<\/strong>(f&#8221;<strong>\\r<\/strong>{bar} {i:3}%&#8221;,&nbsp;end=&#8221;,&nbsp;flush=True)<br>&nbsp;time.sleep(0.05)<br><strong>print<\/strong>()<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u4e0d\u540c\u7684\u8f6c\u4e49\u5b57\u7b26\u6765\u6f14\u793a\u5355\u5f15\u53f7\u3001\u6362\u884c\u7b26\u3001\u5236\u8868\u7b26\u3001\u9000\u683c\u7b26\u3001\u6362\u9875\u7b26\u3001ASCII\u3001\u4e8c\u8fdb\u5236\u3001\u516b\u8fdb\u5236\u6570\u548c\u5341\u516d\u8fdb\u5236\u6570\u7684\u6548\u679c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b<\/h2>\n\n\n\n<p><strong>print<\/strong>(&#8216;<strong>\\&#8217;<\/strong>Hello, world!<strong>\\&#8217;<\/strong>&#8216;)&nbsp;# \u8f93\u51fa\uff1a&#8217;Hello, world!&#8217;<\/p>\n\n\n\n<p><strong>print<\/strong>(&#8220;Hello, world!<strong>\\n<\/strong>How are you?&#8221;)&nbsp;# \u8f93\u51fa\uff1aHello, world!<br>&nbsp;# &nbsp; &nbsp; &nbsp; How are you?<\/p>\n\n\n\n<p><strong>print<\/strong>(&#8220;Hello, world!<strong>\\t<\/strong>How are you?&#8221;)&nbsp;# \u8f93\u51fa\uff1aHello, world! &nbsp; &nbsp;How are you?<\/p>\n\n\n\n<p><strong>print<\/strong>(&#8220;Hello,<strong>\\b<\/strong>&nbsp;world!&#8221;)&nbsp;# \u8f93\u51fa\uff1aHello world!<\/p>\n\n\n\n<p><strong>print<\/strong>(&#8220;Hello,<strong>\\f<\/strong>&nbsp;world!&#8221;)&nbsp;# \u8f93\u51fa\uff1a<br># Hello,<br># &nbsp;world!<\/p>\n\n\n\n<p><strong>print<\/strong>(&#8220;A \u5bf9\u5e94\u7684 ASCII \u503c\u4e3a\uff1a&#8221;,&nbsp;ord(&#8216;A&#8217;))&nbsp;# \u8f93\u51fa\uff1aA \u5bf9\u5e94\u7684 ASCII \u503c\u4e3a\uff1a 65<\/p>\n\n\n\n<p><strong>print<\/strong>(&#8220;<strong>\\x<\/strong>41 \u4e3a A \u7684 ASCII \u4ee3\u7801&#8221;)&nbsp;# \u8f93\u51fa\uff1aA \u4e3a A \u7684 ASCII \u4ee3\u7801<\/p>\n\n\n\n<p>decimal_number&nbsp;=&nbsp;42<br>binary_number&nbsp;=&nbsp;bin(decimal_number)&nbsp;# \u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236<br><strong>print<\/strong>(&#8216;\u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236:&#8217;,&nbsp;binary_number)&nbsp;# \u8f6c\u6362\u4e3a\u4e8c\u8fdb\u5236: 0b101010<\/p>\n\n\n\n<p>octal_number&nbsp;=&nbsp;oct(decimal_number)&nbsp;# \u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236<br><strong>print<\/strong>(&#8216;\u8f6c\u6362\u4e3a\u516b\u8fdb\u5236:&#8217;,&nbsp;octal_number)&nbsp;# \u8f6c\u6362\u4e3a\u516b\u8fdb\u5236: 0o52<\/p>\n\n\n\n<p>hexadecimal_number&nbsp;=&nbsp;hex(decimal_number)&nbsp;# \u5341\u8fdb\u5236\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236<br><strong>print<\/strong>(&#8216;\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236:&#8217;,&nbsp;hexadecimal_number)&nbsp;# \u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236: 0x2a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python \u5b57\u7b26\u4e32\u8fd0\u7b97\u7b26<\/h2>\n\n\n\n<p>\u4e0b\u8868\u5b9e\u4f8b\u53d8\u91cf a \u503c\u4e3a\u5b57\u7b26\u4e32 &#8220;Hello&#8221;\uff0cb \u53d8\u91cf\u503c\u4e3a &#8220;Python&#8221;\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u64cd\u4f5c\u7b26<\/th><th>\u63cf\u8ff0<\/th><th>\u5b9e\u4f8b<\/th><\/tr><tr><td>+<\/td><td>\u5b57\u7b26\u4e32\u8fde\u63a5<\/td><td>a + b \u8f93\u51fa\u7ed3\u679c\uff1a HelloPython<\/td><\/tr><tr><td>*<\/td><td>\u91cd\u590d\u8f93\u51fa\u5b57\u7b26\u4e32<\/td><td>a*2 \u8f93\u51fa\u7ed3\u679c\uff1aHelloHello<\/td><\/tr><tr><td>[]<\/td><td>\u901a\u8fc7\u7d22\u5f15\u83b7\u53d6\u5b57\u7b26\u4e32\u4e2d\u5b57\u7b26<\/td><td>a[1] \u8f93\u51fa\u7ed3\u679c&nbsp;<strong>e<\/strong><\/td><\/tr><tr><td>[ : ]<\/td><td>\u622a\u53d6\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u9075\u5faa<strong>\u5de6\u95ed\u53f3\u5f00<\/strong>\u539f\u5219\uff0cstr[0:2] \u662f\u4e0d\u5305\u542b\u7b2c 3 \u4e2a\u5b57\u7b26\u7684\u3002<\/td><td>a[1:4] \u8f93\u51fa\u7ed3\u679c&nbsp;<strong>ell<\/strong><\/td><\/tr><tr><td>in<\/td><td>\u6210\u5458\u8fd0\u7b97\u7b26 &#8211; \u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u7ed9\u5b9a\u7684\u5b57\u7b26\u8fd4\u56de True<\/td><td><strong>&#8216;H&#8217; in a<\/strong>&nbsp;\u8f93\u51fa\u7ed3\u679c True<\/td><\/tr><tr><td>not in<\/td><td>\u6210\u5458\u8fd0\u7b97\u7b26 &#8211; \u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u4e0d\u5305\u542b\u7ed9\u5b9a\u7684\u5b57\u7b26\u8fd4\u56de True<\/td><td><strong>&#8216;M&#8217; not in a<\/strong>&nbsp;\u8f93\u51fa\u7ed3\u679c True<\/td><\/tr><tr><td>r\/R<\/td><td>\u539f\u59cb\u5b57\u7b26\u4e32 &#8211; \u539f\u59cb\u5b57\u7b26\u4e32\uff1a\u6240\u6709\u7684\u5b57\u7b26\u4e32\u90fd\u662f\u76f4\u63a5\u6309\u7167\u5b57\u9762\u7684\u610f\u601d\u6765\u4f7f\u7528\uff0c\u6ca1\u6709\u8f6c\u4e49\u7279\u6b8a\u6216\u4e0d\u80fd\u6253\u5370\u7684\u5b57\u7b26\u3002 \u539f\u59cb\u5b57\u7b26\u4e32\u9664\u5728\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5f15\u53f7\u524d\u52a0\u4e0a\u5b57\u6bcd&nbsp;<strong>r<\/strong>\uff08\u53ef\u4ee5\u5927\u5c0f\u5199\uff09\u4ee5\u5916\uff0c\u4e0e\u666e\u901a\u5b57\u7b26\u4e32\u6709\u7740\u51e0\u4e4e\u5b8c\u5168\u76f8\u540c\u7684\u8bed\u6cd5\u3002<\/td><td>print( r&#8217;\\n&#8217; ) print( R&#8217;\\n&#8217; )<\/td><\/tr><tr><td>%<\/td><td>\u683c\u5f0f\u5b57\u7b26\u4e32<\/td><td>\u8bf7\u770b\u4e0b\u4e00\u8282\u5185\u5bb9\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 a = &#8220;Hello&#8221; b = &#8220;Python&#8221; print(&#8220;a + b \u8f93\u51fa\u7ed3\u679c\uff1a&#8221;, a + b) print(&#8220;a * 2 \u8f93\u51fa\u7ed3\u679c\uff1a&#8221;, a * 2) print(&#8220;a[1] \u8f93\u51fa\u7ed3\u679c\uff1a&#8221;, a[1]) print(&#8220;a[1:4] \u8f93\u51fa\u7ed3\u679c\uff1a&#8221;, a[1:4]) if( &#8220;H&#8221; in a) : print(&#8220;H \u5728\u53d8\u91cf a \u4e2d&#8221;) else : print(&#8220;H \u4e0d\u5728\u53d8\u91cf a \u4e2d&#8221;) if( &#8220;M&#8221; not in a) : print(&#8220;M \u4e0d\u5728\u53d8\u91cf a \u4e2d&#8221;) else : print(&#8220;M \u5728\u53d8\u91cf a \u4e2d&#8221;) print (r&#8217;\\n&#8217;) print (R&#8217;\\n&#8217;)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a + b \u8f93\u51fa\u7ed3\u679c\uff1a HelloPython\na * 2 \u8f93\u51fa\u7ed3\u679c\uff1a HelloHello\na[1] \u8f93\u51fa\u7ed3\u679c\uff1a e\na[1:4] \u8f93\u51fa\u7ed3\u679c\uff1a ell\nH \u5728\u53d8\u91cf a \u4e2d\nM \u4e0d\u5728\u53d8\u91cf a \u4e2d\n\\n\n\\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python \u5b57\u7b26\u4e32\u683c\u5f0f\u5316<\/h2>\n\n\n\n<p>Python \u652f\u6301\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u8f93\u51fa \u3002\u5c3d\u7ba1\u8fd9\u6837\u53ef\u80fd\u4f1a\u7528\u5230\u975e\u5e38\u590d\u6742\u7684\u8868\u8fbe\u5f0f\uff0c\u4f46\u6700\u57fa\u672c\u7684\u7528\u6cd5\u662f\u5c06\u4e00\u4e2a\u503c\u63d2\u5165\u5230\u4e00\u4e2a\u6709\u5b57\u7b26\u4e32\u683c\u5f0f\u7b26 %s \u7684\u5b57\u7b26\u4e32\u4e2d\u3002<\/p>\n\n\n\n<p>\u5728 Python \u4e2d\uff0c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u4f7f\u7528\u4e0e C \u4e2d sprintf \u51fd\u6570\u4e00\u6837\u7684\u8bed\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 print (&#8220;\u6211\u53eb %s \u4eca\u5e74 %d \u5c81!&#8221; % (&#8216;\u5c0f\u660e&#8217;, 10))<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u6211\u53eb \u5c0f\u660e \u4eca\u5e74 10 \u5c81!<\/pre>\n\n\n\n<p>python\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u7b26\u53f7:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>&nbsp;&nbsp;&nbsp; \u7b26&nbsp;&nbsp; \u53f7<\/th><th>\u63cf\u8ff0<\/th><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %c<\/td><td>&nbsp;\u683c\u5f0f\u5316\u5b57\u7b26\u53ca\u5176ASCII\u7801<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %s<\/td><td>&nbsp;\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %d<\/td><td>&nbsp;\u683c\u5f0f\u5316\u6574\u6570<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %u<\/td><td>&nbsp;\u683c\u5f0f\u5316\u65e0\u7b26\u53f7\u6574\u578b<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %o<\/td><td>&nbsp;\u683c\u5f0f\u5316\u65e0\u7b26\u53f7\u516b\u8fdb\u5236\u6570<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %x<\/td><td>&nbsp;\u683c\u5f0f\u5316\u65e0\u7b26\u53f7\u5341\u516d\u8fdb\u5236\u6570<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %X<\/td><td>&nbsp;\u683c\u5f0f\u5316\u65e0\u7b26\u53f7\u5341\u516d\u8fdb\u5236\u6570\uff08\u5927\u5199\uff09<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %f<\/td><td>&nbsp;\u683c\u5f0f\u5316\u6d6e\u70b9\u6570\u5b57\uff0c\u53ef\u6307\u5b9a\u5c0f\u6570\u70b9\u540e\u7684\u7cbe\u5ea6<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %e<\/td><td>&nbsp;\u7528\u79d1\u5b66\u8ba1\u6570\u6cd5\u683c\u5f0f\u5316\u6d6e\u70b9\u6570<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %E<\/td><td>&nbsp;\u4f5c\u7528\u540c%e\uff0c\u7528\u79d1\u5b66\u8ba1\u6570\u6cd5\u683c\u5f0f\u5316\u6d6e\u70b9\u6570<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %g<\/td><td>&nbsp;%f\u548c%e\u7684\u7b80\u5199<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %G<\/td><td>&nbsp;%f \u548c %E \u7684\u7b80\u5199<\/td><\/tr><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %p<\/td><td>&nbsp;\u7528\u5341\u516d\u8fdb\u5236\u6570\u683c\u5f0f\u5316\u53d8\u91cf\u7684\u5730\u5740<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u683c\u5f0f\u5316\u64cd\u4f5c\u7b26\u8f85\u52a9\u6307\u4ee4:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u7b26\u53f7<\/th><th>\u529f\u80fd<\/th><\/tr><tr><td>*<\/td><td>\u5b9a\u4e49\u5bbd\u5ea6\u6216\u8005\u5c0f\u6570\u70b9\u7cbe\u5ea6<\/td><\/tr><tr><td>&#8211;<\/td><td>\u7528\u505a\u5de6\u5bf9\u9f50<\/td><\/tr><tr><td>+<\/td><td>\u5728\u6b63\u6570\u524d\u9762\u663e\u793a\u52a0\u53f7( + )<\/td><\/tr><tr><td>&lt;sp&gt;<\/td><td>\u5728\u6b63\u6570\u524d\u9762\u663e\u793a\u7a7a\u683c<\/td><\/tr><tr><td>#<\/td><td>\u5728\u516b\u8fdb\u5236\u6570\u524d\u9762\u663e\u793a\u96f6(&#8216;0&#8242;)\uff0c\u5728\u5341\u516d\u8fdb\u5236\u524d\u9762\u663e\u793a&#8217;0x&#8217;\u6216\u8005&#8217;0X'(\u53d6\u51b3\u4e8e\u7528\u7684\u662f&#8217;x&#8217;\u8fd8\u662f&#8217;X&#8217;)<\/td><\/tr><tr><td>0<\/td><td>\u663e\u793a\u7684\u6570\u5b57\u524d\u9762\u586b\u5145&#8217;0&#8217;\u800c\u4e0d\u662f\u9ed8\u8ba4\u7684\u7a7a\u683c<\/td><\/tr><tr><td>%<\/td><td>&#8216;%%&#8217;\u8f93\u51fa\u4e00\u4e2a\u5355\u4e00\u7684&#8217;%&#8217;<\/td><\/tr><tr><td>(var)<\/td><td>\u6620\u5c04\u53d8\u91cf(\u5b57\u5178\u53c2\u6570)<\/td><\/tr><tr><td>m.n.<\/td><td>m \u662f\u663e\u793a\u7684\u6700\u5c0f\u603b\u5bbd\u5ea6,n \u662f\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570(\u5982\u679c\u53ef\u7528\u7684\u8bdd)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Python2.6 \u5f00\u59cb\uff0c\u65b0\u589e\u4e86\u4e00\u79cd\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u51fd\u6570&nbsp;<a target=\"_blank\" href=\"https:\/\/www.runoob.com\/python\/att-string-format.html\" rel=\"noreferrer noopener\">str.format()<\/a>\uff0c\u5b83\u589e\u5f3a\u4e86\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u7684\u529f\u80fd\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python\u4e09\u5f15\u53f7<\/h2>\n\n\n\n<p>python\u4e09\u5f15\u53f7\u5141\u8bb8\u4e00\u4e2a\u5b57\u7b26\u4e32\u8de8\u591a\u884c\uff0c\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u5305\u542b\u6362\u884c\u7b26\u3001\u5236\u8868\u7b26\u4ee5\u53ca\u5176\u4ed6\u7279\u6b8a\u5b57\u7b26\u3002\u5b9e\u4f8b\u5982\u4e0b<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b(Python 3.0+)<\/h2>\n\n\n\n<p>#!\/usr\/bin\/python3 para_str = &#8220;&#8221;&#8221;\u8fd9\u662f\u4e00\u4e2a\u591a\u884c\u5b57\u7b26\u4e32\u7684\u5b9e\u4f8b \u591a\u884c\u5b57\u7b26\u4e32\u53ef\u4ee5\u4f7f\u7528\u5236\u8868\u7b26 TAB ( \\t )\u3002 \u4e5f\u53ef\u4ee5\u4f7f\u7528\u6362\u884c\u7b26 [ \\n ]\u3002 &#8220;&#8221;&#8221; print (para_str)<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5b9e\u4f8b\u6267\u884c\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u8fd9\u662f\u4e00\u4e2a\u591a\u884c\u5b57\u7b26\u4e32\u7684\u5b9e\u4f8b\n\u591a\u884c\u5b57\u7b26\u4e32\u53ef\u4ee5\u4f7f\u7528\u5236\u8868\u7b26\nTAB (    )\u3002\n\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6362\u884c\u7b26 [ \n ]\u3002<\/pre>\n\n\n\n<p>\u4e09\u5f15\u53f7\u8ba9\u7a0b\u5e8f\u5458\u4ece\u5f15\u53f7\u548c\u7279\u6b8a\u5b57\u7b26\u4e32\u7684\u6ce5\u6f6d\u91cc\u9762\u89e3\u8131\u51fa\u6765\uff0c\u81ea\u59cb\u81f3\u7ec8\u4fdd\u6301\u4e00\u5c0f\u5757\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u662f\u6240\u8c13\u7684WYSIWYG\uff08\u6240\u89c1\u5373\u6240\u5f97\uff09\u683c\u5f0f\u7684\u3002<\/p>\n\n\n\n<p>\u4e00\u4e2a\u5178\u578b\u7684\u7528\u4f8b\u662f\uff0c\u5f53\u4f60\u9700\u8981\u4e00\u5757HTML\u6216\u8005SQL\u65f6\uff0c\u8fd9\u65f6\u7528\u5b57\u7b26\u4e32\u7ec4\u5408\uff0c\u7279\u6b8a\u5b57\u7b26\u4e32\u8f6c\u4e49\u5c06\u4f1a\u975e\u5e38\u7684\u7e41\u7410\u3002<\/p>\n\n\n\n<p>errHTML = &#8221;&#8217; &lt;HTML&gt;&lt;HEAD&gt;&lt;TITLE&gt; Friends CGI Demo&lt;\/TITLE&gt;&lt;\/HEAD&gt; &lt;BODY&gt;&lt;H3&gt;ERROR&lt;\/H3&gt; &lt;B&gt;%s&lt;\/B&gt;&lt;P&gt; &lt;FORM&gt;&lt;INPUT TYPE=button VALUE=Back ONCLICK=&#8221;window.history.back()&#8221;&gt;&lt;\/FORM&gt; &lt;\/BODY&gt;&lt;\/HTML&gt; &#8221;&#8217; cursor.execute(&#8221;&#8217; CREATE TABLE users ( login VARCHAR(8), uid INTEGER, prid INTEGER) &#8221;&#8217;)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">f-string<\/h2>\n\n\n\n<p>f-string \u662f python3.6 \u4e4b\u540e\u7248\u672c\u6dfb\u52a0\u7684\uff0c\u79f0\u4e4b\u4e3a\u5b57\u9762\u91cf\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\uff0c\u662f\u65b0\u7684\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u8bed\u6cd5\u3002<\/p>\n\n\n\n<p>\u4e4b\u524d\u6211\u4eec\u4e60\u60ef\u7528\u767e\u5206\u53f7 (%):<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b<\/h2>\n\n\n\n<p>&gt;&gt;&gt;&nbsp;name&nbsp;=&nbsp;&#8216;Runoob&#8217;<br>&gt;&gt;&gt;&nbsp;&#8216;Hello %s&#8217;&nbsp;% name<br>&#8216;Hello Runoob&#8217;<\/p>\n\n\n\n<p><strong>f-string<\/strong>&nbsp;\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4ee5&nbsp;<strong>f<\/strong>&nbsp;\u5f00\u5934\uff0c\u540e\u9762\u8ddf\u7740\u5b57\u7b26\u4e32\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684\u8868\u8fbe\u5f0f\u7528\u5927\u62ec\u53f7 {} \u5305\u8d77\u6765\uff0c\u5b83\u4f1a\u5c06\u53d8\u91cf\u6216\u8868\u8fbe\u5f0f\u8ba1\u7b97\u540e\u7684\u503c\u66ff\u6362\u8fdb\u53bb\uff0c\u5b9e\u4f8b\u5982\u4e0b\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b<\/h2>\n\n\n\n<p>&gt;&gt;&gt;&nbsp;name&nbsp;=&nbsp;&#8216;Runoob&#8217;<br>&gt;&gt;&gt;&nbsp;f&#8217;Hello {name}&#8217;&nbsp;# \u66ff\u6362\u53d8\u91cf<br>&#8216;Hello Runoob&#8217;<br>&gt;&gt;&gt;&nbsp;f'{1+2}&#8217;&nbsp;&nbsp;# \u4f7f\u7528\u8868\u8fbe\u5f0f<br>&#8216;3&#8217;<\/p>\n\n\n\n<p>&gt;&gt;&gt;&nbsp;w&nbsp;=&nbsp;{&#8216;name&#8217;:&nbsp;&#8216;Runoob&#8217;,&nbsp;&#8216;url&#8217;:&nbsp;&#8216;www.runoob.com&#8217;}<br>&gt;&gt;&gt;&nbsp;f'{w[&#8220;name&#8221;]}: {w[&#8220;url&#8221;]}&#8217;<br>&#8216;Runoob: www.runoob.com&#8217;<\/p>\n\n\n\n<p>\u7528\u4e86\u8fd9\u79cd\u65b9\u5f0f\u660e\u663e\u66f4\u7b80\u5355\u4e86\uff0c\u4e0d\u7528\u518d\u53bb\u5224\u65ad\u4f7f\u7528 %s\uff0c\u8fd8\u662f %d\u3002<\/p>\n\n\n\n<p>\u5728 Python 3.8 \u7684\u7248\u672c\u4e2d\u53ef\u4ee5\u4f7f\u7528&nbsp;<strong>=<\/strong>&nbsp;\u7b26\u53f7\u6765\u62fc\u63a5\u8fd0\u7b97\u8868\u8fbe\u5f0f\u4e0e\u7ed3\u679c\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9e\u4f8b<\/h2>\n\n\n\n<p>&gt;&gt;&gt;&nbsp;x&nbsp;=&nbsp;1<br>&gt;&gt;&gt;&nbsp;<strong>print<\/strong>(f'{x+1}&#8217;)&nbsp;&nbsp;# Python 3.6<br>2<\/p>\n\n\n\n<p>&gt;&gt;&gt;&nbsp;x&nbsp;=&nbsp;1<br>&gt;&gt;&gt;&nbsp;<strong>print<\/strong>(f'{x+1=}&#8217;)&nbsp;&nbsp;# Python 3.8<br>x+1=2<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Unicode \u5b57\u7b26\u4e32<\/h2>\n\n\n\n<p>\u5728Python2\u4e2d\uff0c\u666e\u901a\u5b57\u7b26\u4e32\u662f\u4ee58\u4f4dASCII\u7801\u8fdb\u884c\u5b58\u50a8\u7684\uff0c\u800cUnicode\u5b57\u7b26\u4e32\u5219\u5b58\u50a8\u4e3a16\u4f4dunicode\u5b57\u7b26\u4e32\uff0c\u8fd9\u6837\u80fd\u591f\u8868\u793a\u66f4\u591a\u7684\u5b57\u7b26\u96c6\u3002\u4f7f\u7528\u7684\u8bed\u6cd5\u662f\u5728\u5b57\u7b26\u4e32\u524d\u9762\u52a0\u4e0a\u524d\u7f00&nbsp;<strong>u<\/strong>\u3002<\/p>\n\n\n\n<p>\u5728Python3\u4e2d\uff0c\u6240\u6709\u7684\u5b57\u7b26\u4e32\u90fd\u662fUnicode\u5b57\u7b26\u4e32\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Python \u7684\u5b57\u7b26\u4e32\u5185\u5efa\u51fd\u6570<\/h2>\n\n\n\n<p>Python \u7684\u5b57\u7b26\u4e32\u5e38\u7528\u5185\u5efa\u51fd\u6570\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><th>\u5e8f\u53f7<\/th><th>\u65b9\u6cd5\u53ca\u63cf\u8ff0<\/th><\/tr><tr><td>1<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-capitalize.html\">capitalize()<\/a><br>\u5c06\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u8f6c\u6362\u4e3a\u5927\u5199<\/td><\/tr><tr><td>2<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-center.html\">center(width, fillchar)<\/a>\u8fd4\u56de\u4e00\u4e2a\u6307\u5b9a\u7684\u5bbd\u5ea6 width \u5c45\u4e2d\u7684\u5b57\u7b26\u4e32\uff0cfillchar \u4e3a\u586b\u5145\u7684\u5b57\u7b26\uff0c\u9ed8\u8ba4\u4e3a\u7a7a\u683c\u3002<\/td><\/tr><tr><td>3<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-count.html\">count(str, beg= 0,end=len(string))<\/a><br>\u8fd4\u56de str \u5728 string \u91cc\u9762\u51fa\u73b0\u7684\u6b21\u6570\uff0c\u5982\u679c beg \u6216\u8005 end \u6307\u5b9a\u5219\u8fd4\u56de\u6307\u5b9a\u8303\u56f4\u5185 str \u51fa\u73b0\u7684\u6b21\u6570<\/td><\/tr><tr><td>4<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-decode.html\">bytes.decode(encoding=&#8221;utf-8&#8243;, errors=&#8221;strict&#8221;)<\/a><br>Python3 \u4e2d\u6ca1\u6709 decode \u65b9\u6cd5\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 bytes \u5bf9\u8c61\u7684 decode() \u65b9\u6cd5\u6765\u89e3\u7801\u7ed9\u5b9a\u7684 bytes \u5bf9\u8c61\uff0c\u8fd9\u4e2a bytes \u5bf9\u8c61\u53ef\u4ee5\u7531 str.encode() \u6765\u7f16\u7801\u8fd4\u56de\u3002<\/td><\/tr><tr><td>5<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-encode.html\">encode(encoding=&#8217;UTF-8&#8242;,errors=&#8217;strict&#8217;)<\/a><br>\u4ee5 encoding \u6307\u5b9a\u7684\u7f16\u7801\u683c\u5f0f\u7f16\u7801\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u51fa\u9519\u9ed8\u8ba4\u62a5\u4e00\u4e2aValueError \u7684\u5f02\u5e38\uff0c\u9664\u975e errors \u6307\u5b9a\u7684\u662f&#8217;ignore&#8217;\u6216\u8005&#8217;replace&#8217;<\/td><\/tr><tr><td>6<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-endswith.html\">endswith(suffix, beg=0, end=len(string))<\/a><br>\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u4ee5 suffix \u7ed3\u675f\uff0c\u5982\u679c beg \u6216\u8005 end \u6307\u5b9a\u5219\u68c0\u67e5\u6307\u5b9a\u7684\u8303\u56f4\u5185\u662f\u5426\u4ee5 suffix \u7ed3\u675f\uff0c\u5982\u679c\u662f\uff0c\u8fd4\u56de True,\u5426\u5219\u8fd4\u56de False\u3002<\/td><\/tr><tr><td>7<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-expandtabs.html\">expandtabs(tabsize=8)<\/a><br>\u628a\u5b57\u7b26\u4e32 string \u4e2d\u7684 tab \u7b26\u53f7\u8f6c\u4e3a\u7a7a\u683c\uff0ctab \u7b26\u53f7\u9ed8\u8ba4\u7684\u7a7a\u683c\u6570\u662f 8 \u3002<\/td><\/tr><tr><td>8<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-find.html\">find(str, beg=0, end=len(string))<\/a><br>\u68c0\u6d4b str \u662f\u5426\u5305\u542b\u5728\u5b57\u7b26\u4e32\u4e2d\uff0c\u5982\u679c\u6307\u5b9a\u8303\u56f4 beg \u548c end \uff0c\u5219\u68c0\u67e5\u662f\u5426\u5305\u542b\u5728\u6307\u5b9a\u8303\u56f4\u5185\uff0c\u5982\u679c\u5305\u542b\u8fd4\u56de\u5f00\u59cb\u7684\u7d22\u5f15\u503c\uff0c\u5426\u5219\u8fd4\u56de-1<\/td><\/tr><tr><td>9<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-index.html\">index(str, beg=0, end=len(string))<\/a><br>\u8ddffind()\u65b9\u6cd5\u4e00\u6837\uff0c\u53ea\u4e0d\u8fc7\u5982\u679cstr\u4e0d\u5728\u5b57\u7b26\u4e32\u4e2d\u4f1a\u62a5\u4e00\u4e2a\u5f02\u5e38\u3002<\/td><\/tr><tr><td>10<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-isalnum.html\">isalnum()<\/a><br>\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u7531\u5b57\u6bcd\u548c\u6570\u5b57\u7ec4\u6210\uff0c\u5373\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5b57\u6bcd\u6216\u6570\u5b57\u3002\u5982\u679c\u5b57\u7b26\u4e32\u81f3\u5c11\u6709\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u4e14\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5b57\u6bcd\u6216\u6570\u5b57\uff0c\u5219\u8fd4\u56de True\uff1b\u5426\u5219\u8fd4\u56de False\u3002<\/td><\/tr><tr><td>11<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-isalpha.html\">isalpha()<\/a><br>\u5982\u679c\u5b57\u7b26\u4e32\u81f3\u5c11\u6709\u4e00\u4e2a\u5b57\u7b26\u5e76\u4e14\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5b57\u6bcd\u6216\u4e2d\u6587\u5b57\u5219\u8fd4\u56de True, \u5426\u5219\u8fd4\u56de False<\/td><\/tr><tr><td>12<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-isdigit.html\">isdigit()<\/a><br>\u5982\u679c\u5b57\u7b26\u4e32\u53ea\u5305\u542b\u6570\u5b57\u5219\u8fd4\u56de True \u5426\u5219\u8fd4\u56de False..<\/td><\/tr><tr><td>13<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-islower.html\">islower()<\/a><br>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u81f3\u5c11\u4e00\u4e2a\u533a\u5206\u5927\u5c0f\u5199\u7684\u5b57\u7b26\uff0c\u5e76\u4e14\u6240\u6709\u8fd9\u4e9b(\u533a\u5206\u5927\u5c0f\u5199\u7684)\u5b57\u7b26\u90fd\u662f\u5c0f\u5199\uff0c\u5219\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False<\/td><\/tr><tr><td>14<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-isnumeric.html\">isnumeric()<\/a><br>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u53ea\u5305\u542b\u6570\u5b57\u5b57\u7b26\uff0c\u5219\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False<\/td><\/tr><tr><td>15<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-isspace.html\">isspace()<\/a><br>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u53ea\u5305\u542b\u7a7a\u767d\uff0c\u5219\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False.<\/td><\/tr><tr><td>16<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-istitle.html\">istitle()<\/a><br>\u5982\u679c\u5b57\u7b26\u4e32\u662f\u6807\u9898\u5316\u7684(\u89c1 title())\u5219\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False<\/td><\/tr><tr><td>17<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-isupper.html\">isupper()<\/a><br>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u81f3\u5c11\u4e00\u4e2a\u533a\u5206\u5927\u5c0f\u5199\u7684\u5b57\u7b26\uff0c\u5e76\u4e14\u6240\u6709\u8fd9\u4e9b(\u533a\u5206\u5927\u5c0f\u5199\u7684)\u5b57\u7b26\u90fd\u662f\u5927\u5199\uff0c\u5219\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False<\/td><\/tr><tr><td>18<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-join.html\">join(seq)<\/a><br>\u4ee5\u6307\u5b9a\u5b57\u7b26\u4e32\u4f5c\u4e3a\u5206\u9694\u7b26\uff0c\u5c06 seq \u4e2d\u6240\u6709\u7684\u5143\u7d20(\u7684\u5b57\u7b26\u4e32\u8868\u793a)\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32<\/td><\/tr><tr><td>19<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-len.html\">len(string)<\/a><br>\u8fd4\u56de\u5b57\u7b26\u4e32\u957f\u5ea6<\/td><\/tr><tr><td>20<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-ljust.html\">ljust(width[, fillchar])<\/a><br>\u8fd4\u56de\u4e00\u4e2a\u539f\u5b57\u7b26\u4e32\u5de6\u5bf9\u9f50,\u5e76\u4f7f\u7528 fillchar \u586b\u5145\u81f3\u957f\u5ea6 width \u7684\u65b0\u5b57\u7b26\u4e32\uff0cfillchar \u9ed8\u8ba4\u4e3a\u7a7a\u683c\u3002<\/td><\/tr><tr><td>21<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-lower.html\">lower()<\/a><br>\u8f6c\u6362\u5b57\u7b26\u4e32\u4e2d\u6240\u6709\u5927\u5199\u5b57\u7b26\u4e3a\u5c0f\u5199.<\/td><\/tr><tr><td>22<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-lstrip.html\">lstrip()<\/a><br>\u622a\u6389\u5b57\u7b26\u4e32\u5de6\u8fb9\u7684\u7a7a\u683c\u6216\u6307\u5b9a\u5b57\u7b26\u3002<\/td><\/tr><tr><td>23<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-maketrans.html\">maketrans()<\/a><br>\u521b\u5efa\u5b57\u7b26\u6620\u5c04\u7684\u8f6c\u6362\u8868\uff0c\u5bf9\u4e8e\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\u7684\u6700\u7b80\u5355\u7684\u8c03\u7528\u65b9\u5f0f\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u9700\u8981\u8f6c\u6362\u7684\u5b57\u7b26\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4e5f\u662f\u5b57\u7b26\u4e32\u8868\u793a\u8f6c\u6362\u7684\u76ee\u6807\u3002<\/td><\/tr><tr><td>24<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-max.html\">max(str)<\/a><br>\u8fd4\u56de\u5b57\u7b26\u4e32 str \u4e2d\u6700\u5927\u7684\u5b57\u6bcd\u3002<\/td><\/tr><tr><td>25<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-min.html\">min(str)<\/a><br>\u8fd4\u56de\u5b57\u7b26\u4e32 str \u4e2d\u6700\u5c0f\u7684\u5b57\u6bcd\u3002<\/td><\/tr><tr><td>26<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-replace.html\">replace(old, new [, max])<\/a><br>\u628a \u5c06\u5b57\u7b26\u4e32\u4e2d\u7684 old \u66ff\u6362\u6210 new,\u5982\u679c max \u6307\u5b9a\uff0c\u5219\u66ff\u6362\u4e0d\u8d85\u8fc7 max \u6b21\u3002<\/td><\/tr><tr><td>27<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-rfind.html\">rfind(str, beg=0,end=len(string))<\/a><br>\u7c7b\u4f3c\u4e8e find()\u51fd\u6570\uff0c\u4e0d\u8fc7\u662f\u4ece\u53f3\u8fb9\u5f00\u59cb\u67e5\u627e.<\/td><\/tr><tr><td>28<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-rindex.html\">rindex( str, beg=0, end=len(string))<\/a><br>\u7c7b\u4f3c\u4e8e index()\uff0c\u4e0d\u8fc7\u662f\u4ece\u53f3\u8fb9\u5f00\u59cb.<\/td><\/tr><tr><td>29<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-rjust.html\">rjust(width,[, fillchar])<\/a><br>\u8fd4\u56de\u4e00\u4e2a\u539f\u5b57\u7b26\u4e32\u53f3\u5bf9\u9f50,\u5e76\u4f7f\u7528fillchar(\u9ed8\u8ba4\u7a7a\u683c\uff09\u586b\u5145\u81f3\u957f\u5ea6 width \u7684\u65b0\u5b57\u7b26\u4e32<\/td><\/tr><tr><td>30<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-rstrip.html\">rstrip()<\/a><br>\u5220\u9664\u5b57\u7b26\u4e32\u672b\u5c3e\u7684\u7a7a\u683c\u6216\u6307\u5b9a\u5b57\u7b26\u3002<\/td><\/tr><tr><td>31<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-split.html\">split(str=&#8221;&#8221;, num=string.count(str))<\/a><br>\u4ee5 str \u4e3a\u5206\u9694\u7b26\u622a\u53d6\u5b57\u7b26\u4e32\uff0c\u5982\u679c num \u6709\u6307\u5b9a\u503c\uff0c\u5219\u4ec5\u622a\u53d6 num+1 \u4e2a\u5b50\u5b57\u7b26\u4e32<\/td><\/tr><tr><td>32<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-splitlines.html\">splitlines([keepends])<\/a><br>\u6309\u7167\u884c(&#8216;\\r&#8217;, &#8216;\\r\\n&#8217;, \\n&#8217;)\u5206\u9694\uff0c\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u5404\u884c\u4f5c\u4e3a\u5143\u7d20\u7684\u5217\u8868\uff0c\u5982\u679c\u53c2\u6570 keepends \u4e3a False\uff0c\u4e0d\u5305\u542b\u6362\u884c\u7b26\uff0c\u5982\u679c\u4e3a True\uff0c\u5219\u4fdd\u7559\u6362\u884c\u7b26\u3002<\/td><\/tr><tr><td>33<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-startswith.html\">startswith(substr, beg=0,end=len(string))<\/a><br>\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u662f\u4ee5\u6307\u5b9a\u5b50\u5b57\u7b26\u4e32 substr \u5f00\u5934\uff0c\u662f\u5219\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\u3002\u5982\u679cbeg \u548c end \u6307\u5b9a\u503c\uff0c\u5219\u5728\u6307\u5b9a\u8303\u56f4\u5185\u68c0\u67e5\u3002<\/td><\/tr><tr><td>34<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-strip.html\">strip([chars])<\/a><br>\u5728\u5b57\u7b26\u4e32\u4e0a\u6267\u884c lstrip()\u548c rstrip()<\/td><\/tr><tr><td>35<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-swapcase.html\">swapcase()<\/a><br>\u5c06\u5b57\u7b26\u4e32\u4e2d\u5927\u5199\u8f6c\u6362\u4e3a\u5c0f\u5199\uff0c\u5c0f\u5199\u8f6c\u6362\u4e3a\u5927\u5199<\/td><\/tr><tr><td>36<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-title.html\">title()<\/a><br>\u8fd4\u56de&#8221;\u6807\u9898\u5316&#8221;\u7684\u5b57\u7b26\u4e32,\u5c31\u662f\u8bf4\u6240\u6709\u5355\u8bcd\u90fd\u662f\u4ee5\u5927\u5199\u5f00\u59cb\uff0c\u5176\u4f59\u5b57\u6bcd\u5747\u4e3a\u5c0f\u5199(\u89c1 istitle())<\/td><\/tr><tr><td>37<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-translate.html\">translate(table, deletechars=&#8221;&#8221;)<\/a><br>\u6839\u636e table \u7ed9\u51fa\u7684\u8868(\u5305\u542b 256 \u4e2a\u5b57\u7b26)\u8f6c\u6362 string \u7684\u5b57\u7b26, \u8981\u8fc7\u6ee4\u6389\u7684\u5b57\u7b26\u653e\u5230 deletechars \u53c2\u6570\u4e2d<\/td><\/tr><tr><td>38<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-upper.html\">upper()<\/a><br>\u8f6c\u6362\u5b57\u7b26\u4e32\u4e2d\u7684\u5c0f\u5199\u5b57\u6bcd\u4e3a\u5927\u5199<\/td><\/tr><tr><td>39<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-zfill.html\">zfill (width)<\/a><br>\u8fd4\u56de\u957f\u5ea6\u4e3a width \u7684\u5b57\u7b26\u4e32\uff0c\u539f\u5b57\u7b26\u4e32\u53f3\u5bf9\u9f50\uff0c\u524d\u9762\u586b\u51450<\/td><\/tr><tr><td>40<\/td><td><a href=\"https:\/\/www.runoob.com\/python3\/python3-string-isdecimal.html\">isdecimal()<\/a><br>\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u53ea\u5305\u542b\u5341\u8fdb\u5236\u5b57\u7b26\uff0c\u5982\u679c\u662f\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5b57\u7b26\u4e32\u662f Python \u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5f15\u53f7(&#038;nb&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":480,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-1"],"views":645,"_links":{"self":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/comments?post=583"}],"version-history":[{"count":1,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":584,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/posts\/583\/revisions\/584"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media\/480"}],"wp:attachment":[{"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/media?parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/categories?post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.pyteam.cn\/index.php\/wp-json\/wp\/v2\/tags?post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}