{"id":5481,"date":"2022-04-02T21:30:26","date_gmt":"2022-04-02T13:30:26","guid":{"rendered":"https:\/\/egonlin.com\/?p=5481"},"modified":"2022-04-02T21:30:26","modified_gmt":"2022-04-02T13:30:26","slug":"03-03-%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%b1%bb%e5%9e%8b%e5%8f%8a%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=5481","title":{"rendered":"03-03 \u5b57\u7b26\u4e32\u7c7b\u578b\u53ca\u64cd\u4f5c"},"content":{"rendered":"<h1>\u4e00\u3001\u6982\u8ff0<\/h1>\n<ul>\n<li>\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u8868\u793a<\/li>\n<li>\u5b57\u7b26\u4e32\u64cd\u4f5c\u7b26<\/li>\n<li>\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570<\/li>\n<li>\u5b57\u7b26\u4e32\u5904\u7406\u65b9\u6cd5<\/li>\n<li>\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u683c\u5f0f\u5316<\/li>\n<\/ul>\n<h1>\u4e8c\u3001\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u8868\u793a<\/h1>\n<p>\u75310\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684\u6709\u5e8f\u5b57\u7b26\u5e8f\u5217<\/p>\n<ul>\n<li>\u5b57\u7b26\u4e32\u7531\u4e00\u5bf9\u5355\u5f15\u53f7\u6216\u4e00\u5bf9\u53cc\u5f15\u53f7\u8868\u793a\uff1a<code>&quot;\u8bf7\u8f93\u5165\u5e26\u6709\u7b26\u53f7\u7684\u6e29\u5ea6\u503c: &quot;<\/code>\u6216\u8005 <code>&#039;C&#039;<\/code><\/li>\n<li>\u5b57\u7b26\u4e32\u662f\u5b57\u7b26\u7684\u6709\u5e8f\u5e8f\u5217\uff0c\u53ef\u4ee5\u5bf9\u5176\u4e2d\u7684\u5b57\u7b26\u8fdb\u884c\u7d22\u5f15\uff1a<code>&quot;\u8bf7&quot;<\/code> \u662f <code>&quot;\u8bf7\u8f93\u5165\u5e26\u6709\u7b26\u53f7\u7684\u6e29\u5ea6\u503c: &quot;<\/code> \u7684\u7b2c0\u4e2a\u5b57\u7b26<\/li>\n<\/ul>\n<p>\u5b57\u7b26\u4e32\u6709 2\u7c7b\u51714\u79cd \u8868\u793a\u65b9\u6cd5<\/p>\n<ul>\n<li>\u7531\u4e00\u5bf9\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u8868\u793a\uff0c\u4ec5\u8868\u793a\u5355\u884c\u5b57\u7b26\u4e32\uff1a<code>&quot;\u8bf7\u8f93\u5165\u5e26\u6709\u7b26\u53f7\u7684\u6e29\u5ea6\u503c: &quot;<\/code>\u6216\u8005 <code>&#039;C&#039;<\/code><\/li>\n<li>\u7531\u4e00\u5bf9\u4e09\u5355\u5f15\u53f7\u6216\u4e09\u53cc\u5f15\u53f7\u8868\u793a\uff0c\u53ef\u8868\u793a\u591a\u884c\u5b57\u7b26\u4e32<\/li>\n<\/ul>\n<pre><code class=\"language-python\">&#039;&#039;&#039;\nPython\n    \u8bed\u8a00\n&#039;&#039;&#039;<\/code><\/pre>\n<ul>\n<li>\u5982\u679c\u5e0c\u671b\u5728\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u53cc\u5f15\u53f7\u6216\u5355\u5f15\u53f7\u5462\uff1f\uff1a<code>&#039;\u8fd9\u91cc\u6709\u4e2a\u53cc\u5f15\u53f7(&quot;)&#039;<\/code> \u6216\u8005 <code>&quot;\u8fd9\u91cc\u6709\u4e2a\u5355\u5f15\u53f7(&#039;)&quot;<\/code><\/li>\n<li>\u5982\u679c\u5e0c\u671b\u5728\u5b57\u7b26\u4e32\u4e2d\u65e2\u5305\u62ec\u5355\u5f15\u53f7\u53c8\u5305\u62ec\u53cc\u5f15\u53f7\u5462\uff1f\uff1a<code>&#039;&#039;&#039; \u8fd9\u91cc\u65e2\u6709\u5355\u5f15\u53f7(&#039;)\u53c8\u6709\u53cc\u5f15\u53f7 (&quot;) &#039;&#039;&#039;<\/code><\/li>\n<\/ul>\n<h2>2.1 \u5b57\u7b26\u4e32\u7684\u5e8f\u53f7<\/h2>\n<p>\u6b63\u5411\u9012\u589e\u5e8f\u53f7 \u548c \u53cd\u5411\u9012\u51cf\u5e8f\u53f7<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/\u5b57\u7b26\u4e32\u7c7b\u578b\u53ca\u64cd\u4f5c-1.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2022\/04\/\u5b57\u7b26\u4e32\u7c7b\u578b\u53ca\u64cd\u4f5c-1.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<h2>2.2 \u5b57\u7b26\u4e32\u7684\u4f7f\u7528<\/h2>\n<p>\u4f7f\u7528[ ]\u83b7\u53d6\u5b57\u7b26\u4e32\u4e2d\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26<\/p>\n<ul>\n<li>\u7d22\u5f15\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u5355\u4e2a\u5b57\u7b26 <code>&lt;\u5b57\u7b26\u4e32&gt;[M]<\/code>\uff1a<code>&quot;\u8bf7\u8f93\u5165\u5e26\u6709\u7b26\u53f7\u7684\u6e29\u5ea6\u503c: &quot;[0]<\/code> \u6216\u8005 <code>TempStr[-1]<\/code><\/li>\n<li>\u5207\u7247\uff1a\u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u4e00\u6bb5\u5b57\u7b26\u5b50\u4e32 <code>&lt;\u5b57\u7b26\u4e32&gt;[M: N]<\/code>\uff1a<code>&quot;\u8bf7\u8f93\u5165\u5e26\u6709\u7b26\u53f7\u7684\u6e29\u5ea6\u503c: &quot;[1:3]<\/code> \u6216\u8005 <code>TempStr[0:-1]<\/code><\/li>\n<\/ul>\n<h2>2.3 \u5b57\u7b26\u4e32\u5207\u7247\u9ad8\u7ea7\u7528\u6cd5<\/h2>\n<p>\u4f7f\u7528<code>[M: N: K]<\/code>\u6839\u636e\u6b65\u957f\u5bf9\u5b57\u7b26\u4e32\u5207\u7247<\/p>\n<ul>\n<li><code>&lt;\u5b57\u7b26\u4e32&gt;[M: N]\uff0cM<\/code>\u7f3a\u5931\u8868\u793a\u81f3\u5f00\u5934\uff0cN\u7f3a\u5931\u8868\u793a\u81f3\u7ed3\u5c3e\uff1a<code>&quot;\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341&quot;[:3]<\/code> \u7ed3\u679c\u662f <code>&quot;\u3007\u4e00\u4e8c&quot;<\/code><\/li>\n<li>&lt;\u5b57\u7b26\u4e32&gt;[M: N: K]\uff0c\u6839\u636e\u6b65\u957fK\u5bf9\u5b57\u7b26\u4e32\u5207\u7247\uff1a\n<ul>\n<li><code>&quot;\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341&quot;[1:8:2]<\/code> \u7ed3\u679c\u662f <code>&quot;\u4e00\u4e09\u4e94\u4e03&quot;<\/code><\/li>\n<li><code>&quot;\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d\u5341&quot;[::-1]<\/code> \u7ed3\u679c\u662f <code>&quot;\u5341\u4e5d\u516b\u4e03\u516d\u4e94\u56db\u4e09\u4e8c\u4e00\u3007<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>2.4 \u5b57\u7b26\u4e32\u7684\u7279\u6b8a\u5b57\u7b26\u2014\u2014\u8f6c\u4e49\u7b26<\/h2>\n<ul>\n<li>\u8f6c\u4e49\u7b26\u8868\u8fbe\u7279\u5b9a\u5b57\u7b26\u7684\u672c\u610f\uff1a<code>&quot;\u8fd9\u91cc\u6709\u4e2a\u53cc\u5f15\u53f7(\\&quot;)&quot;<\/code> \u7ed3\u679c\u4e3a <code>\u8fd9\u91cc\u6709\u4e2a\u53cc\u5f15\u53f7(&quot;)<\/code><\/li>\n<li>\u8f6c\u4e49\u7b26\u5f62\u6210\u4e00\u4e9b\u7ec4\u5408\uff0c\u8868\u8fbe\u4e00\u4e9b\u4e0d\u53ef\u6253\u5370\u7684\u542b\u4e49\uff1a<code>&quot;\\b&quot;<\/code>\u56de\u9000 <code>&quot;\\n&quot;<\/code>\u6362\u884c(\u5149\u6807\u79fb\u52a8\u5230\u4e0b\u884c\u9996) <code>&quot;\\r&quot;<\/code> \u56de\u8f66(\u5149\u6807\u79fb\u52a8\u5230\u672c\u884c\u9996)<\/li>\n<\/ul>\n<h1>\u4e09\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c\u7b26<\/h1>\n<h2>3.1 \u75310\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u7ec4\u6210\u7684\u6709\u5e8f\u5b57\u7b26\u5e8f\u5217<\/h2>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26\u53ca\u4f7f\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">x+y<\/td>\n<td style=\"text-align: center;\">\u8fde\u63a5\u4e24\u4e2a\u5b57\u7b26\u4e32x\u548cy<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">n<em>x \u6216 x<\/em>n<\/td>\n<td style=\"text-align: center;\">\u590d\u5236n\u6b21\u5b57\u7b26\u4e32x<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x in s<\/td>\n<td style=\"text-align: center;\">\u5982\u679cx\u662fs\u7684\u5b50\u4e32\uff0c\u8fd4\u56deTrue\uff0c\u5426\u5219\u8fd4\u56deFalse<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>3.2 \u83b7\u53d6\u661f\u671f\u5b57\u7b26\u4e32<\/h2>\n<ul>\n<li>\u8f93\u5165\uff1a1-7\u7684\u6574\u6570\uff0c\u8868\u793a\u661f\u671f\u51e0<\/li>\n<li>\u8f93\u51fa\uff1a\u8f93\u5165\u6574\u6570\u5bf9\u5e94\u7684\u661f\u671f\u5b57\u7b26\u4e32<\/li>\n<li>\u4f8b\u5982\uff1a\u8f93\u51653\uff0c\u8f93\u51fa \u661f\u671f\u4e09<\/li>\n<\/ul>\n<pre><code class=\"language-python\"># WeekNamePrintV1.py\n\nweekStr = &quot;\u661f\u671f\u4e00\u661f\u671f\u4e8c\u661f\u671f\u4e09\u661f\u671f\u56db\u661f\u671f\u4e94\u661f\u671f\u516d\u661f\u671f\u65e5&quot; \nweekId = eval(input(&quot;\u8bf7\u8f93\u5165\u661f\u671f\u6570\u5b57(1-7)\uff1a&quot;))\npos = (weekId \u2013 1 ) * 3\nprint(weekStr[pos: pos+3])<\/code><\/pre>\n<pre><code class=\"language-python\"># WeekNamePrintV2.py\n\nweekStr = &quot;\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u65e5&quot;\nweekId = eval(input(&quot;\u8bf7\u8f93\u5165\u661f\u671f\u6570\u5b57(1-7)\uff1a&quot;)) \nprint(&quot;\u661f\u671f&quot; + weekStr[weekId-1])<\/code><\/pre>\n<h1>\u56db\u3001\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570<\/h1>\n<p>\u4e00\u4e9b\u4ee5\u51fd\u6570\u5f62\u5f0f\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u5904\u7406\u529f\u80fd<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u51fd\u6570\u53ca\u4f7f\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">len(x)<\/td>\n<td style=\"text-align: center;\">\u957f\u5ea6\uff0c\u8fd4\u56de\u5b57\u7b26\u4e32x\u7684\u957f\u5ea6\uff1a<code>len(&quot;\u4e00\u4e8c\u4e09456&quot;)<\/code> \u7ed3\u679c\u4e3a 6<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">str(x)<\/td>\n<td style=\"text-align: center;\">\u4efb\u610f\u7c7b\u578bx\u6240\u5bf9\u5e94\u7684\u5b57\u7b26\u4e32\u5f62\u5f0f\uff1a<code>str(1.23)<\/code>\u7ed3\u679c\u4e3a&quot;1.23&quot; <code>str([1,2])<\/code>\u7ed3\u679c\u4e3a&quot;[1,2]&quot;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">hex(x) \u6216 oct(x)<\/td>\n<td style=\"text-align: center;\">\u6574\u6570x\u7684\u5341\u516d\u8fdb\u5236\u6216\u516b\u8fdb\u5236\u5c0f\u5199\u5f62\u5f0f\u5b57\u7b26\u4e32\uff1a<code>hex(425)<\/code>\u7ed3\u679c\u4e3a&quot;0x1a9&quot; <code>oct(425)<\/code>\u7ed3\u679c\u4e3a&quot;0o651&quot;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">chr(u)<\/td>\n<td style=\"text-align: center;\">x\u4e3aUnicode\u7f16\u7801\uff0c\u8fd4\u56de\u5176\u5bf9\u5e94\u7684\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">ord(x)<\/td>\n<td style=\"text-align: center;\">x\u4e3a\u5b57\u7b26\uff0c\u8fd4\u56de\u5176\u5bf9\u5e94\u7684Unicode\u7f16\u7801<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>4.1 Unicode\u7f16\u7801<\/h2>\n<p>Python\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u65b9\u5f0f<\/p>\n<ul>\n<li>\u7edf\u4e00\u5b57\u7b26\u7f16\u7801\uff0c\u5373\u8986\u76d6\u51e0\u4e4e\u6240\u6709\u5b57\u7b26\u7684\u7f16\u7801\u65b9\u5f0f<\/li>\n<li>\u4ece0\u52301114111 (0x10FFFF)\u7a7a\u95f4\uff0c\u6bcf\u4e2a\u7f16\u7801\u5bf9\u5e94\u4e00\u4e2a\u5b57\u7b26<\/li>\n<li>Python\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5b57\u7b26\u90fd\u662fUnicode\u7f16\u7801\u5b57\u7b26<\/li>\n<\/ul>\n<h3>4.1.1 \u4e00\u4e9b\u6709\u8da3\u7684\u4f8b\u5b50<\/h3>\n<pre><code class=\"language-python\">print(&quot;1+1=2&quot; + chr(10004))\nprint(&quot;\u8fd9\u4e2a\u5b57\u7b26\u2648\u7684Unicode\u503c\u662f\uff1a&quot; + str(ord(&quot;\u2648&quot;)))\nfor i in range(12):\n    print(chr(9800 + i), end=&quot;&quot;)\n\n&quot;&quot;&quot;\n\u2648\u2649\u264a\u264b\u264c\u264d\u264e\u264f\u2650\u2651\u2652\u2653\n&quot;&quot;&quot;<\/code><\/pre>\n<h1>\u4e94\u3001\u5b57\u7b26\u4e32\u5904\u7406\u65b9\u6cd5<\/h1>\n<p>&quot;\u65b9\u6cd5&quot;\u5728\u7f16\u7a0b\u4e2d\u662f\u4e00\u4e2a\u4e13\u6709\u540d\u8bcd<\/p>\n<ul>\n<li>&quot;\u65b9\u6cd5&quot;\u7279\u6307<code>&lt;a&gt;.&lt;b&gt;()<\/code>\u98ce\u683c\u4e2d\u7684\u51fd\u6570<code>&lt;b&gt;()<\/code><\/li>\n<li>\u65b9\u6cd5\u672c\u8eab\u4e5f\u662f\u51fd\u6570\uff0c\u4f46\u4e0e<code>&lt;a&gt;<\/code>\u6709\u5173\uff0c<code>&lt;a&gt;.&lt;b&gt;()<\/code>\u98ce\u683c\u4f7f\u7528<\/li>\n<li>\u5b57\u7b26\u4e32\u53ca\u53d8\u91cf\u4e5f\u662f<code>&lt;a&gt;<\/code>\uff0c\u5b58\u5728\u4e00\u4e9b\u65b9\u6cd5<\/li>\n<\/ul>\n<h1>\u516d\u3001\u5b57\u7b26\u4e32\u5185\u7f6e\u65b9\u6cd5<\/h1>\n<p>\u4e00\u4e9b\u4ee5\u65b9\u6cd5\u5f62\u5f0f\u63d0\u4f9b\u7684\u5b57\u7b26\u4e32\u5904\u7406\u529f\u80fd<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u65b9\u6cd5\u53ca\u4f7f\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">str.lower() \u6216 str.upper()<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u526f\u672c\uff0c\u5168\u90e8\u5b57\u7b26\u5c0f\u5199\/\u5927\u5199\uff1a<code>&quot;AbCdEfGh&quot;.lower()<\/code> \u7ed3\u679c\u4e3a &quot;abcdefgh&quot;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">str.split(sep=None)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u4e00\u4e2a\u5217\u8868\uff0c\u7531str\u6839\u636esep\u88ab\u5206\u9694\u7684\u90e8\u5206\u7ec4\u6210 \uff1a<code>&quot;A,B,C&quot;.split(&quot;,&quot;)<\/code> \u7ed3\u679c\u4e3a[&#8216;A&#8217;,&#8217;B&#8217;,&#8217;C&#8217;]<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">str.count(sub)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u5b50\u4e32sub\u5728str\u4e2d\u51fa\u73b0\u7684\u6b21\u6570\uff1a<code>&quot;a apple a day&quot;.count(&quot;a&quot;)<\/code> \u7ed3\u679c\u4e3a 4<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">str.replace(old, new)<\/td>\n<td style=\"text-align: center;\">\u8fd4\u56de\u5b57\u7b26\u4e32str\u526f\u672c\uff0c\u6240\u6709old\u5b50\u4e32\u88ab\u66ff\u6362\u4e3anew \uff1a<code>&quot;python&quot;.replace(&quot;n&quot;,&quot;n456&quot;)<\/code> \u7ed3\u679c\u4e3a &quot;python456&quot;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">str.center(width[,fillchar])<\/td>\n<td style=\"text-align: center;\">\u5b57\u7b26\u4e32str\u6839\u636e\u5bbd\u5ea6width\u5c45\u4e2d\uff0cfillchar\u53ef\u9009\uff1a<code>&quot;python&quot;.center(20,&quot;=&quot;)<\/code> \u7ed3\u679c\u4e3a &#8216;=======python=======&#8217;<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">str.strip(chars)<\/td>\n<td style=\"text-align: center;\">\u4ecestr\u4e2d\u53bb\u6389\u5728\u5176\u5de6\u4fa7\u548c\u53f3\u4fa7chars\u4e2d\u5217\u51fa\u7684\u5b57\u7b26\uff1a<code>&quot;= python= &quot;.strip(&quot; =np&quot;)<\/code> \u7ed3\u679c\u4e3a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&quot;ytho&quot;str.join(iter)|\u5728iter\u53d8\u91cf\u9664\u6700\u540e\u5143\u7d20\u5916\u6bcf\u4e2a\u5143\u7d20\u540e\u589e\u52a0\u4e00\u4e2a\uff1a<code>str &quot;,&quot;.join(&quot;12345&quot;)<\/code> \u7ed3\u679c\u4e3a &quot;1,2,3,4,5&quot; #\u4e3b\u8981\u7528\u4e8e\u5b57\u7b26\u4e32\u5206\u9694\u7b49<\/p>\n<h1>\u4e03\u3001\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u683c\u5f0f\u5316<\/h1>\n<p>\u683c\u5f0f\u5316\u662f\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u683c\u5f0f\u8868\u8fbe\u7684\u65b9\u5f0f<\/p>\n<ul>\n<li>\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u4f7f\u7528.format()\u65b9\u6cd5\uff0c\u7528\u6cd5\u5982\u4e0b\uff1a<code>&lt;\u6a21\u677f\u5b57\u7b26\u4e32&gt;.format(&lt;\u9017\u53f7\u5206\u9694\u7684\u53c2\u6570&gt;)<\/code><\/li>\n<li>\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u4f7f\u7528f-string\u65b9\u6cd5\uff0c\u7528\u6cd5\u5982\u4e0b\uff1a<code>f&lt;\u6a21\u677f{&lt;\u9017\u53f7\u5206\u9694\u7684\u53c2\u6570&gt;}\u5b57\u7b26\u4e32&gt;<\/code><\/li>\n<\/ul>\n<h2>7.1 f-string\u65b9\u6cd5\u7684\u683c\u5f0f\u63a7\u5236<\/h2>\n<p>{&lt;\u53c2\u6570\u5e8f\u53f7&gt; \uff1a &lt;\u683c\u5f0f\u63a7\u5236\u6807\u8bb0&gt;}<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">:<\/th>\n<th style=\"text-align: center;\">&lt;\u586b\u5145&gt;<\/th>\n<th style=\"text-align: center;\">&lt;\u5bf9\u9f50&gt;<\/th>\n<th style=\"text-align: center;\">&lt;\u5bbd\u5ea6&gt;<\/th>\n<th style=\"text-align: center;\">&lt;,&gt;<\/th>\n<th style=\"text-align: center;\">&lt;.\u7cbe\u5ea6&gt;<\/th>\n<th style=\"text-align: center;\">&lt;\u7c7b\u578b&gt;<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u5f15\u5bfc\u7b26\u53f7<\/td>\n<td style=\"text-align: center;\">\u7528\u4e8e\u586b\u5145\u7684\u5355\u4e2a\u5b57\u7b26<\/td>\n<td style=\"text-align: center;\">&lt; \u5de6\u5bf9\u9f50 &gt; \u53f3\u5bf9\u9f50 ^ \u5c45\u4e2d\u5bf9\u9f50<\/td>\n<td style=\"text-align: center;\">\u69fd\u8bbe\u5b9a\u7684\u8f93\u51fa\u5bbd\u5ea6<\/td>\n<td style=\"text-align: center;\">\u6570\u5b57\u7684\u5343\u4f4d\u5206\u9694\u7b26<\/td>\n<td style=\"text-align: center;\">\u6d6e\u70b9\u6570\u5c0f\u6570 \u6216 \u5b57\u7b26\u4e32\u6700\u5927\u8f93\u51fa\u957f\u5ea6<\/td>\n<td style=\"text-align: center;\">\u6574\u6570\u7c7b\u578b <code>b,c,d,o,x,X<\/code> \u6d6e\u70b9\u6570\u7c7b\u578b<code>e,E,f,%<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<pre><code class=\"language-python\">&quot;{0:=^20}&quot;.format(&#039;PYTHON&#039;)\n&#039;&#039;&#039;=======PYTHON=======&#039;&#039;&#039;\n\n&quot;{0:*&gt;20}&quot;.format(&quot;BIT&quot;)\n&#039;&#039;&#039;*****************BIT&#039;&#039;&#039;\n\n&quot;{:10}&quot;.format(&quot;BIT&quot;)\n&#039;&#039;&#039;BIT       &#039;&#039;&#039;<\/code><\/pre>\n<h1>\u516b\u3001\u5355\u5143\u5c0f\u7ed3<\/h1>\n<ul>\n<li>\u6b63\u5411\u9012\u589e\u5e8f\u53f7\u3001\u53cd\u5411\u9012\u51cf\u5e8f\u53f7\u3001&lt;\u5b57\u7b26\u4e32&gt;[M:N:K]<\/li>\n<li>+\u3001*\u3001len()\u3001str()\u3001hex()\u3001oct()\u3001ord()\u3001chr()<\/li>\n<li>.lower()\u3001.upper()\u3001.split()\u3001.count()\u3001.replace()<\/li>\n<li>.center()\u3001.strip()\u3001.join(\uff09\u3001.format()\u683c\u5f0f\u5316<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6982\u8ff0 \u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u8868\u793a \u5b57\u7b26\u4e32\u64cd\u4f5c\u7b26 \u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570 \u5b57\u7b26\u4e32\u5904\u7406\u65b9\u6cd5 \u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u683c\u5f0f\u5316 \u4e8c\u3001\u5b57\u7b26\u4e32\u7c7b\u578b\u7684 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5482,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[371,374],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5481"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5481"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5481\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/5482"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}