{"id":1164706,"date":"2025-01-15T15:10:58","date_gmt":"2025-01-15T07:10:58","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1164706.html"},"modified":"2025-01-15T15:11:02","modified_gmt":"2025-01-15T07:11:02","slug":"python%e5%a6%82%e4%bd%95%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%a4%a7%e5%86%99","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1164706.html","title":{"rendered":"python\u5982\u4f55\u5b57\u7b26\u4e32\u5927\u5199"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25205230\/b45455c4-6c79-4ece-abca-e1c18b32ae74.webp\" alt=\"python\u5982\u4f55\u5b57\u7b26\u4e32\u5927\u5199\" \/><\/p>\n<p><p> <strong>Python\u5b57\u7b26\u4e32\u5927\u5199\u53ef\u4ee5\u4f7f\u7528upper()\u65b9\u6cd5\u3001\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u8868\u3001\u4f7f\u7528ASCII\u7801\u5b9e\u73b0<\/strong><\/p>\n<\/p>\n<p><p>\u8be6\u7ec6\u63cf\u8ff0\uff1a<strong>upper()\u65b9\u6cd5<\/strong>\u662fPython\u5185\u7f6e\u5b57\u7b26\u4e32\u65b9\u6cd5\u4e4b\u4e00\uff0c\u5b83\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\u3002\u4f7f\u7528\u6b64\u65b9\u6cd5\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u5728\u5b57\u7b26\u4e32\u5bf9\u8c61\u4e0a\u8c03\u7528upper()\u65b9\u6cd5\u5373\u53ef\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u53d8\u91cfmy_string = &quot;hello world&quot;\uff0c\u8c03\u7528my_string.upper()\u5c06\u8fd4\u56de&quot;HELLO WORLD&quot;\u3002upper()\u65b9\u6cd5\u4e0d\u4ec5\u64cd\u4f5c\u7b80\u4fbf\uff0c\u800c\u4e14\u6267\u884c\u6548\u7387\u8f83\u9ad8\uff0c\u662f\u5c06\u5b57\u7b26\u4e32\u5927\u5199\u7684\u5e38\u7528\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001upper()\u65b9\u6cd5<\/h2>\n<\/p>\n<p><h3>\u7b80\u4ecb<\/h3>\n<\/p>\n<p><p>Python\u7684upper()\u65b9\u6cd5\u662f\u5b57\u7b26\u4e32\u5bf9\u8c61\u7684\u5185\u7f6e\u65b9\u6cd5\u3002\u5b83\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u7684\u6240\u6709\u5b57\u6bcd\u90fd\u88ab\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u6539\u53d8\u539f\u59cb\u5b57\u7b26\u4e32\uff0c\u56e0\u4e3a\u5b57\u7b26\u4e32\u662f\u4e0d\u53ef\u53d8\u7684\uff08immutable\uff09\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u793a\u4f8b 1\uff1a\u57fa\u672c\u7528\u6cd5<\/p>\n<p>my_string = &quot;hello world&quot;<\/p>\n<p>upper_string = my_string.upper()<\/p>\n<p>print(upper_string)  # \u8f93\u51fa: &quot;HELLO WORLD&quot;<\/p>\n<h2><strong>\u793a\u4f8b 2\uff1a\u5305\u542b\u6570\u5b57\u548c\u7b26\u53f7<\/strong><\/h2>\n<p>my_string = &quot;Python 3.8!&quot;<\/p>\n<p>upper_string = my_string.upper()<\/p>\n<p>print(upper_string)  # \u8f93\u51fa: &quot;PYTHON 3.8!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f18\u70b9<\/h3>\n<\/p>\n<ul>\n<li><strong>\u7b80\u5355\u6613\u7528<\/strong>\uff1a\u53ea\u9700\u8c03\u7528\u5b57\u7b26\u4e32\u5bf9\u8c61\u7684upper()\u65b9\u6cd5\u5373\u53ef\u3002<\/li>\n<li><strong>\u9ad8\u6548<\/strong>\uff1a\u5185\u7f6e\u65b9\u6cd5\u6267\u884c\u901f\u5ea6\u5feb\u3002<\/li>\n<\/ul>\n<p><h3>\u7f3a\u70b9<\/h3>\n<\/p>\n<ul>\n<li><strong>\u9002\u7528\u4e8e\u82f1\u6587\u5b57\u6bcd<\/strong>\uff1aupper()\u65b9\u6cd5\u4e3b\u8981\u9488\u5bf9\u82f1\u6587\u5b57\u6bcd\u7684\u5927\u5c0f\u5199\u8f6c\u6362\uff0c\u5bf9\u4e8e\u5176\u4ed6\u8bed\u8a00\u7684\u5b57\u7b26\u53ef\u80fd\u6ca1\u6709\u6548\u679c\u3002<\/li>\n<\/ul>\n<p><h2>\u4e8c\u3001\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u8868<\/h2>\n<\/p>\n<p><h3>\u7b80\u4ecb<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u5b57\u6bcd\u8f6c\u6362\u8868\uff0c\u53ef\u4ee5\u5c06\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5b57\u7b26\u8f6c\u6362\u89c4\u5219\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u8bed\u8a00\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u5b57\u6bcd\u8f6c\u6362\u8868<\/p>\n<p>lowercase_letters = &quot;abcdefghijklmnopqrstuvwxyz&quot;<\/p>\n<p>uppercase_letters = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;<\/p>\n<p>translation_table = str.maketrans(lowercase_letters, uppercase_letters)<\/p>\n<h2><strong>\u4f7f\u7528\u8f6c\u6362\u8868<\/strong><\/h2>\n<p>my_string = &quot;hello world&quot;<\/p>\n<p>upper_string = my_string.translate(translation_table)<\/p>\n<p>print(upper_string)  # \u8f93\u51fa: &quot;HELLO WORLD&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f18\u70b9<\/h3>\n<\/p>\n<ul>\n<li><strong>\u7075\u6d3b\u6027\u9ad8<\/strong>\uff1a\u53ef\u4ee5\u81ea\u5b9a\u4e49\u8f6c\u6362\u89c4\u5219\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u8bed\u8a00\u3002<\/li>\n<li><strong>\u53ef\u6269\u5c55\u6027\u5f3a<\/strong>\uff1a\u53ef\u4ee5\u6839\u636e\u9700\u8981\u6dfb\u52a0\u66f4\u591a\u5b57\u7b26\u7684\u8f6c\u6362\u3002<\/li>\n<\/ul>\n<p><h3>\u7f3a\u70b9<\/h3>\n<\/p>\n<ul>\n<li><strong>\u590d\u6742\u6027<\/strong>\uff1a\u9700\u8981\u624b\u52a8\u521b\u5efa\u8f6c\u6362\u8868\uff0c\u6b65\u9aa4\u76f8\u5bf9\u7e41\u7410\u3002<\/li>\n<\/ul>\n<p><h2>\u4e09\u3001\u4f7f\u7528ASCII\u7801\u5b9e\u73b0<\/h2>\n<\/p>\n<p><h3>\u7b80\u4ecb<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528ASCII\u7801\uff0c\u53ef\u4ee5\u624b\u52a8\u5c06\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd\u3002\u8fd9\u79cd\u65b9\u6cd5\u9700\u8981\u5bf9\u6bcf\u4e2a\u5b57\u7b26\u8fdb\u884c\u5224\u65ad\u548c\u8f6c\u6362\uff0c\u9002\u5408\u4e86\u89e3\u5b57\u7b26\u7f16\u7801\u7684\u7528\u6237\u3002<\/p>\n<\/p>\n<p><h3>\u4f7f\u7528\u793a\u4f8b<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">def to_upper(string):<\/p>\n<p>    result = &quot;&quot;<\/p>\n<p>    for char in string:<\/p>\n<p>        # \u5982\u679c\u662f\u5c0f\u5199\u5b57\u6bcd\uff0c\u5219\u8f6c\u6362\u4e3a\u5927\u5199\u5b57\u6bcd<\/p>\n<p>        if &#39;a&#39; &lt;= char &lt;= &#39;z&#39;:<\/p>\n<p>            result += chr(ord(char) - 32)<\/p>\n<p>        else:<\/p>\n<p>            result += char<\/p>\n<p>    return result<\/p>\n<h2><strong>\u793a\u4f8b<\/strong><\/h2>\n<p>my_string = &quot;hello world&quot;<\/p>\n<p>upper_string = to_upper(my_string)<\/p>\n<p>print(upper_string)  # \u8f93\u51fa: &quot;HELLO WORLD&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4f18\u70b9<\/h3>\n<\/p>\n<ul>\n<li><strong>\u7cbe\u7ec6\u63a7\u5236<\/strong>\uff1a\u53ef\u4ee5\u624b\u52a8\u63a7\u5236\u6bcf\u4e2a\u5b57\u7b26\u7684\u8f6c\u6362\u8fc7\u7a0b\u3002<\/li>\n<li><strong>\u9002\u7528\u4e8e\u5404\u79cd\u5b57\u7b26<\/strong>\uff1a\u53ef\u4ee5\u6839\u636eASCII\u7801\u8868\u8fdb\u884c\u4efb\u610f\u5b57\u7b26\u8f6c\u6362\u3002<\/li>\n<\/ul>\n<p><h3>\u7f3a\u70b9<\/h3>\n<\/p>\n<ul>\n<li><strong>\u4ee3\u7801\u590d\u6742\u5ea6\u9ad8<\/strong>\uff1a\u9700\u8981\u7f16\u5199\u66f4\u591a\u4ee3\u7801\u8fdb\u884c\u5b57\u7b26\u5224\u65ad\u548c\u8f6c\u6362\u3002<\/li>\n<li><strong>\u6548\u7387\u8f83\u4f4e<\/strong>\uff1a\u7531\u4e8e\u9700\u8981\u9010\u4e2a\u5b57\u7b26\u5224\u65ad\u548c\u8f6c\u6362\uff0c\u6267\u884c\u6548\u7387\u8f83\u4f4e\u3002<\/li>\n<\/ul>\n<p><h2>\u56db\u3001\u6027\u80fd\u5bf9\u6bd4<\/h2>\n<\/p>\n<p><h3>\u7b80\u4ecb<\/h3>\n<\/p>\n<p><p>\u4e0d\u540c\u65b9\u6cd5\u5728\u6027\u80fd\u4e0a\u6709\u6240\u5dee\u5f02\uff0c\u9009\u62e9\u9002\u5408\u7684\u65b9\u5f0f\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u6267\u884c\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u5bf9\u4e09\u79cd\u65b9\u6cd5\u7684\u6027\u80fd\u5bf9\u6bd4\u3002<\/p>\n<\/p>\n<p><h3>\u6027\u80fd\u6d4b\u8bd5\u4ee3\u7801<\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<h2><strong>\u6d4b\u8bd5upper()\u65b9\u6cd5<\/strong><\/h2>\n<p>start_time = time.time()<\/p>\n<p>for _ in range(1000000):<\/p>\n<p>    &quot;hello world&quot;.upper()<\/p>\n<p>print(&quot;upper()\u65b9\u6cd5\u6267\u884c\u65f6\u95f4:&quot;, time.time() - start_time)<\/p>\n<h2><strong>\u6d4b\u8bd5\u8f6c\u6362\u8868\u65b9\u6cd5<\/strong><\/h2>\n<p>lowercase_letters = &quot;abcdefghijklmnopqrstuvwxyz&quot;<\/p>\n<p>uppercase_letters = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;<\/p>\n<p>translation_table = str.maketrans(lowercase_letters, uppercase_letters)<\/p>\n<p>start_time = time.time()<\/p>\n<p>for _ in range(1000000):<\/p>\n<p>    &quot;hello world&quot;.translate(translation_table)<\/p>\n<p>print(&quot;\u8f6c\u6362\u8868\u65b9\u6cd5\u6267\u884c\u65f6\u95f4:&quot;, time.time() - start_time)<\/p>\n<h2><strong>\u6d4b\u8bd5ASCII\u7801\u65b9\u6cd5<\/strong><\/h2>\n<p>def to_upper(string):<\/p>\n<p>    result = &quot;&quot;<\/p>\n<p>    for char in string:<\/p>\n<p>        if &#39;a&#39; &lt;= char &lt;= &#39;z&#39;:<\/p>\n<p>            result += chr(ord(char) - 32)<\/p>\n<p>        else:<\/p>\n<p>            result += char<\/p>\n<p>    return result<\/p>\n<p>start_time = time.time()<\/p>\n<p>for _ in range(1000000):<\/p>\n<p>    to_upper(&quot;hello world&quot;)<\/p>\n<p>print(&quot;ASCII\u7801\u65b9\u6cd5\u6267\u884c\u65f6\u95f4:&quot;, time.time() - start_time)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6027\u80fd\u6d4b\u8bd5\u7ed3\u679c<\/h3>\n<\/p>\n<p><p>\u6839\u636e\u6d4b\u8bd5\u7ed3\u679c\uff0cupper()\u65b9\u6cd5\u7684\u6267\u884c\u65f6\u95f4\u6700\u77ed\uff0c\u8f6c\u6362\u8868\u65b9\u6cd5\u6b21\u4e4b\uff0cASCII\u7801\u65b9\u6cd5\u7684\u6267\u884c\u65f6\u95f4\u6700\u957f\u3002\u56e0\u6b64\uff0c\u5728\u4e0d\u9700\u8981\u7279\u6b8a\u5b57\u7b26\u8f6c\u6362\u7684\u60c5\u51b5\u4e0b\uff0cupper()\u65b9\u6cd5\u662f\u6700\u63a8\u8350\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u5e94\u7528\u573a\u666f<\/h2>\n<\/p>\n<p><h3>\u6587\u672c\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u6587\u672c\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u7ecf\u5e38\u9700\u8981\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\uff0c\u4f8b\u5982\u5904\u7406\u7528\u6237\u8f93\u5165\u3001\u751f\u6210\u62a5\u544a\u7b49\u3002upper()\u65b9\u6cd5\u5728\u8fd9\u4e9b\u573a\u666f\u4e2d\u975e\u5e38\u9002\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u6570\u636e\u89c4\u8303\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5904\u7406\u4e2d\uff0c\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u89c4\u8303\u5316\u5904\u7406\uff0c\u5c06\u6240\u6709\u5b57\u7b26\u8f6c\u6362\u4e3a\u5927\u5199\u53ef\u4ee5\u7edf\u4e00\u6570\u636e\u683c\u5f0f\uff0c\u4fbf\u4e8e\u540e\u7eed\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h3>\u7f16\u7801\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u5728\u7f16\u5199\u591a\u8bed\u8a00\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u8868\u6216ASCII\u7801\u65b9\u6cd5\u8fdb\u884c\u5b57\u7b26\u8f6c\u6362\uff0c\u4ece\u800c\u652f\u6301\u66f4\u591a\u8bed\u8a00\u7684\u5b57\u7b26\u8f6c\u6362\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h3>\u6027\u80fd\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u9700\u8981\u5bf9\u5927\u91cf\u5b57\u7b26\u4e32\u8fdb\u884c\u5927\u5199\u8f6c\u6362\u65f6\uff0c\u53ef\u4ee5\u9009\u62e9\u6027\u80fd\u6700\u4f73\u7684\u65b9\u6cd5\uff0c\u63d0\u9ad8\u4ee3\u7801\u6267\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5b57\u7b26\u4e32\u5927\u5199\u53ef\u4ee5\u901a\u8fc7upper()\u65b9\u6cd5\u3001\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u8868\u548c\u4f7f\u7528ASCII\u7801\u4e09\u79cd\u65b9\u6cd5\u5b9e\u73b0\u3002<strong>upper()\u65b9\u6cd5<\/strong>\u7b80\u5355\u6613\u7528\uff0c\u9002\u7528\u4e8e\u5927\u591a\u6570\u60c5\u51b5\uff1b<strong>\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u8868<\/strong>\u7075\u6d3b\u6027\u9ad8\uff0c\u9002\u7528\u4e8e\u591a\u8bed\u8a00\u5b57\u7b26\u8f6c\u6362\uff1b<strong>\u4f7f\u7528ASCII\u7801<\/strong>\u7cbe\u7ec6\u63a7\u5236\uff0c\u9002\u7528\u4e8e\u4e86\u89e3\u5b57\u7b26\u7f16\u7801\u7684\u7528\u6237\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u7684\u5185\u7f6e\u65b9\u6cd5<code>upper()<\/code>\u6765\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5927\u5199\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u4f1a\u6539\u53d8\u539f\u59cb\u5b57\u7b26\u4e32\uff0c\u800c\u662f\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5927\u5199\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">original_string = &quot;hello world&quot;\nuppercase_string = original_string.upper()\nprint(uppercase_string)  # \u8f93\u51fa: HELLO WORLD\n<\/code><\/pre>\n<p><strong>Python\u4e2d\u662f\u5426\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u5b57\u7b26\u4e32\u7684\u5927\u5199\uff1f<\/strong><br \/>\u9664\u4e86<code>upper()<\/code>\u65b9\u6cd5\uff0cPython\u8fd8\u63d0\u4f9b\u4e86<code>str.capitalize()<\/code>\u548c<code>str.title()<\/code>\u65b9\u6cd5\u3002<code>capitalize()<\/code>\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u7684\u9996\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\uff0c\u5176\u4f59\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5c0f\u5199\uff1b\u800c<code>title()<\/code>\u65b9\u6cd5\u5219\u5c06\u6bcf\u4e2a\u5355\u8bcd\u7684\u9996\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">title_string = &quot;hello world&quot;\ncapitalized_string = title_string.capitalize()\nprint(capitalized_string)  # \u8f93\u51fa: Hello world\n\ntitled_string = title_string.title()\nprint(titled_string)  # \u8f93\u51fa: Hello World\n<\/code><\/pre>\n<p><strong>\u662f\u5426\u53ef\u4ee5\u4f7f\u7528Python\u4e2d\u7684\u5176\u4ed6\u5e93\u6765\u5904\u7406\u5b57\u7b26\u4e32\u7684\u5927\u5199\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u9664\u4e86Python\u5185\u7f6e\u7684\u65b9\u6cd5\u5916\uff0c\u4f7f\u7528<code>pandas<\/code>\u5e93\u5904\u7406\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u5229\u7528<code>str.upper()<\/code>\u65b9\u6cd5\u5bf9\u6570\u636e\u6846\u4e2d\u7684\u5b57\u7b26\u4e32\u5217\u8fdb\u884c\u5927\u5199\u8f6c\u6362\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = {&#39;names&#39;: [&#39;alice&#39;, &#39;bob&#39;, &#39;charlie&#39;]}\ndf = pd.DataFrame(data)\ndf[&#39;names&#39;] = df[&#39;names&#39;].str.upper()\nprint(df)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u4f1a\u628a\u6570\u636e\u6846\u4e2d\u7684\u6240\u6709\u540d\u5b57\u8f6c\u6362\u4e3a\u5927\u5199\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5b57\u7b26\u4e32\u5927\u5199\u53ef\u4ee5\u4f7f\u7528upper()\u65b9\u6cd5\u3001\u5927\u5199\u5b57\u6bcd\u8f6c\u6362\u8868\u3001\u4f7f\u7528ASCII\u7801\u5b9e\u73b0 \u8be6\u7ec6\u63cf\u8ff0\uff1aupper( [&hellip;]","protected":false},"author":3,"featured_media":1164715,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1164706"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1164706"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1164706\/revisions"}],"predecessor-version":[{"id":1164716,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1164706\/revisions\/1164716"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1164715"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1164706"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1164706"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1164706"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}