{"id":205010,"date":"2025-05-29T10:08:32","date_gmt":"2025-05-29T02:08:32","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205010\/"},"modified":"2025-05-29T10:08:32","modified_gmt":"2025-05-29T02:08:32","slug":"%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205010\/","title":{"rendered":"\u5b57\u7b26\u4e32\u51fd\u6570"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5b57\u7b26\u4e32\u51fd\u6570<\/h1>\n<p>\u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5b57\u7b26\u4e32\u51fd\u6570\u300b<\/span>\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u8bf7\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427\uff01\u4ee5\u4e0b\u5185\u5bb9\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u662f\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6216\u8005\u5df2\u7ecf\u662f\u5927\u4f6c\u7ea7\u522b\u4e86\uff0c\u90fd\u975e\u5e38\u6b22\u8fce\u4e5f\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u7ed9\u6211\u5efa\u8bae\u8bc4\u8bba\u54c8~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732172643673edb6367cf0.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python \u5b57\u7b26\u4e32\u51fd\u6570\uff1a<\/strong><\/p>\n<p>python \u6709\u4e00\u7ec4\u53ef\u4ee5\u5728\u5b57\u7b26\u4e32\u4e0a\u4f7f\u7528\u7684\u5185\u7f6e\u65b9\u6cd5\u3002<\/p>\n<p>\u6240\u6709\u5b57\u7b26\u4e32\u65b9\u6cd5\u90fd\u4f1a\u8fd4\u56de\u65b0\u503c\u3002\u4ed6\u4eec\u4e0d\u4f1a\u6539\u53d8\u539f\u59cb\u5b57\u7b26\u4e32\u3002<\/p>\n<p>1.**capitalize(): **\u5c06\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5927\u5199\u3002<\/p>\n<pre>name = \"pritha\"\nprint(name.capitalize()) \n<\/pre>\n<pre>pritha\n<\/pre>\n<p>2.<strong>casefold()<\/strong>:\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5c0f\u5199<\/p>\n<pre>name = \"pritha\"\nprint(name.casefold()) \n<\/pre>\n<pre>pritha\n<\/pre>\n<p>3.<strong>center():<\/strong>\u8fd4\u56de\u5c45\u4e2d\u7684\u5b57\u7b26\u4e32<\/p>\n<pre>name = \"pritha\"\nprint(name.center(10,\"-\")) \n<\/pre>\n<pre>--pritha--\n<\/pre>\n<p>4.<strong>count():<\/strong>\u8fd4\u56de\u6307\u5b9a\u503c\u5728\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u7684\u6b21\u6570<\/p>\n<pre>name = \"lakshmipritha\"\nprint(name.count('a')) \n<\/pre>\n<pre>2\n<\/pre>\n<p>5.<strong>encode():<\/strong>\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u7248\u672c<\/p>\n<pre>name = \"lakshmipritha\"\nprint(name.encode()) \n<\/pre>\n<pre>b'lakshmipritha'\n<\/pre>\n<p>6.<strong>endswith():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4ee5\u6307\u5b9a\u503c\u7ed3\u5c3e\u5219\u8fd4\u56de true<\/p>\n<pre>name = \"lakshmi pritha\"\nprint(name.endswith('pritha')) \n<\/pre>\n<pre>true\n<\/pre>\n<p>7.<strong>find():<\/strong>\u5728\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u6307\u5b9a\u503c\u5e76\u8fd4\u56de\u627e\u5230\u5b83\u7684\u4f4d\u7f6e<\/p>\n<pre>name = \"lakshmi pritha\"\nprint(name.find('pritha')) \n<\/pre>\n<pre>8\n<\/pre>\n<p>8.<strong>format():<\/strong>\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4e2d\u7684\u6307\u5b9a\u503c<\/p>\n<pre>name = \"hello, {}. welcome to {}.\"\nprint(name.format(\"pritha\", \"python\")) \n<\/pre>\n<pre>hello, pritha. welcome to python.\n<\/pre>\n<p>9.<strong>format_map():<\/strong>\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u4e2d\u7684\u6307\u5b9a\u503c<\/p>\n<pre>text = \"my name is {name} and i am {age} years old.\"\ndata = {\"name\": \"pritha\", \"age\":30 }\nprint(text.format_map(data))\n\n<\/pre>\n<pre>my name is pritha and i am 30 years old.\n<\/pre>\n<p>10.<strong>index():<\/strong>\u5728\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u6307\u5b9a\u503c\u5e76\u8fd4\u56de\u627e\u5230\u5b83\u7684\u4f4d\u7f6e<\/p>\n<pre>name= \"lakshmi pritha\"\nposition = name.index(\"pritha\")\nprint(position)\n<\/pre>\n<pre>8\n<\/pre>\n<p>11.<strong>isalnum():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5b57\u6bcd\u6570\u5b57\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>12.<strong>isalpha():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u5728\u5b57\u6bcd\u8868\u4e2d\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>13.<strong>isacii():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f ascii \u5b57\u7b26\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>14.<strong>isdecimal():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u5c0f\u6570\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>15.<strong>isdigit():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u6570\u5b57\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>16.<strong>isidentifier():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u662f\u6807\u8bc6\u7b26\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>17.<strong>islower():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u5747\u4e3a\u5c0f\u5199\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>18.<strong>isnumeric():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u6570\u5b57\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>19.<strong>isprintable():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u5747\u53ef\u6253\u5370\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>20.<strong>isspace():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u90fd\u662f\u7a7a\u683c\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>21.<strong>istitle():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u9075\u5faa\u6807\u9898\u89c4\u5219\uff0c\u5219\u8fd4\u56de true<\/p>\n<p>22.<strong>isupper():<\/strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u7b26\u5747\u4e3a\u5927\u5199\uff0c\u5219\u8fd4\u56de true<\/p>\n<pre>name = \"pritha\"\nprint(name.isalnum())\nprint(name.isalpha())\nprint(name.isascii())\nprint(name.isdecimal())\nprint(name.isdigit())\nprint(name.isidentifier())\nprint(name.islower())\nprint(name.isnumeric())\nprint(name.isprintable())\nprint(name.isspace())\nprint(name.istitle())\nprint(name.isupper())\n\n<\/pre>\n<pre>True\nTrue\nTrue\nFalse\nFalse\nTrue\nTrue\nFalse\nTrue\nFalse\nFalse\nFalse\n\n\n\n\n\n<\/pre>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5b57\u7b26\u4e32\u51fd\u6570\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b57\u7b26\u4e32\u51fd\u6570 \u4eca\u5929\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u300a\u5b57&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205010","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205010"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205010\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}