{"id":1061959,"date":"2024-12-31T15:47:14","date_gmt":"2024-12-31T07:47:14","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1061959.html"},"modified":"2024-12-31T15:47:17","modified_gmt":"2024-12-31T07:47:17","slug":"%e6%95%b0%e7%bb%84%e5%a6%82%e4%bd%95%e7%ad%9b%e9%80%89%e5%a4%a7%e5%86%99%e5%ad%97%e6%af%8dpython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1061959.html","title":{"rendered":"\u6570\u7ec4\u5982\u4f55\u7b5b\u9009\u5927\u5199\u5b57\u6bcdPython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/aadffe5b-9153-41b7-b487-878e2e220ce8.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u6570\u7ec4\u5982\u4f55\u7b5b\u9009\u5927\u5199\u5b57\u6bcdPython\" \/><\/p>\n<p><p> <strong>\u6570\u7ec4\u5982\u4f55\u7b5b\u9009\u5927\u5199\u5b57\u6bcdPython<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u7b5b\u9009\u6570\u7ec4\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c<strong>\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570filter\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\u3002\u5176\u4e2d\uff0c\u5217\u8868\u63a8\u5bfc\u5f0f\u662f\u6700\u5e38\u7528\u4e14\u7b80\u6d01\u7684\u65b9\u6cd5\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u7b5b\u9009\u6570\u7ec4\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\uff0c\u5e76\u7ed3\u5408\u5176\u4ed6\u65b9\u6cd5\u8fdb\u884c\u6bd4\u8f83\u548c\u8865\u5145\u3002<\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u7b5b\u9009\u5927\u5199\u5b57\u6bcd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u7b5b\u9009\u5927\u5199\u5b57\u6bcd<\/p>\n<p>array = [&#39;a&#39;, &#39;B&#39;, &#39;c&#39;, &#39;D&#39;, &#39;e&#39;, &#39;F&#39;]<\/p>\n<p>uppercase_letters = [char for char in array if char.isupper()]<\/p>\n<p>print(uppercase_letters)  # \u8f93\u51fa: [&#39;B&#39;, &#39;D&#39;, &#39;F&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5217\u8868\u63a8\u5bfc\u5f0f<\/strong>\u662f\u4e00\u79cd\u7b80\u6d01\u800c\u4f18\u96c5\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u4e00\u884c\u4ee3\u7801\u4e2d\u5b9e\u73b0\u8fc7\u6ee4\u64cd\u4f5c\u3002\u5217\u8868\u63a8\u5bfc\u5f0f\u7684\u8bed\u6cd5\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">[expression for item in iterable if condition]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5176\u4e2d\uff0c<code>expression<\/code>\u662f\u6700\u7ec8\u4fdd\u5b58\u5728\u5217\u8868\u4e2d\u7684\u5143\u7d20\uff0c<code>item<\/code>\u662f\u8fed\u4ee3\u8fc7\u7a0b\u4e2d\u6bcf\u6b21\u8bbf\u95ee\u7684\u5143\u7d20\uff0c<code>iterable<\/code>\u662f\u88ab\u8fed\u4ee3\u7684\u5bf9\u8c61\uff0c<code>condition<\/code>\u662f\u8fc7\u6ee4\u6761\u4ef6\u3002\u5728\u672c\u4f8b\u4e2d\uff0c<code>char.isupper()<\/code>\u662f\u6761\u4ef6\uff0c\u7528\u4e8e\u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u5927\u5199\u5b57\u6bcd\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570filter<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5217\u8868\u63a8\u5bfc\u5f0f\uff0cPython\u8fd8\u63d0\u4f9b\u4e86<code>filter<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u4e8e\u7b5b\u9009\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002<code>filter<\/code>\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528filter\u51fd\u6570\u7b5b\u9009\u5927\u5199\u5b57\u6bcd<\/p>\n<p>array = [&#39;a&#39;, &#39;B&#39;, &#39;c&#39;, &#39;D&#39;, &#39;e&#39;, &#39;F&#39;]<\/p>\n<p>uppercase_letters = list(filter(str.isupper, array))<\/p>\n<p>print(uppercase_letters)  # \u8f93\u51fa: [&#39;B&#39;, &#39;D&#39;, &#39;F&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>filter<\/strong>\u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570\uff1a\u4e00\u4e2a\u51fd\u6570\u548c\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002\u5b83\u4f1a\u5c06\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u5982\u679c\u51fd\u6570\u8fd4\u56de<code>True<\/code>\uff0c\u5219\u8be5\u5143\u7d20\u4f1a\u88ab\u4fdd\u7559\u4e0b\u6765\u3002<code>str.isupper<\/code>\u662f\u4e00\u4e2a\u5185\u7f6e\u65b9\u6cd5\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f5c\u4e3a\u7b5b\u9009\u51fd\u6570\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7b5b\u9009\u5927\u5199\u5b57\u6bcd<\/h3>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u800c\u7075\u6d3b\u7684\u5b57\u7b26\u4e32\u5339\u914d\u5de5\u5177\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u7b5b\u9009\u6570\u7ec4\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\u3002Python\u4e2d\u7684<code>re<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u652f\u6301\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u529f\u80fd\u3002\u4e0b\u9762\u662f\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7b5b\u9009\u5927\u5199\u5b57\u6bcd\u7684\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u7b5b\u9009\u5927\u5199\u5b57\u6bcd<\/strong><\/h2>\n<p>array = [&#39;a&#39;, &#39;B&#39;, &#39;c&#39;, &#39;D&#39;, &#39;e&#39;, &#39;F&#39;]<\/p>\n<p>uppercase_letters = [char for char in array if re.match(r&#39;[A-Z]&#39;, char)]<\/p>\n<p>print(uppercase_letters)  # \u8f93\u51fa: [&#39;B&#39;, &#39;D&#39;, &#39;F&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>re.match(r&#39;[A-Z]&#39;, char)<\/code>\u7528\u4e8e\u5224\u65ad\u5b57\u7b26\u662f\u5426\u4e3a\u5927\u5199\u5b57\u6bcd\u3002\u6b63\u5219\u8868\u8fbe\u5f0f<code>[A-Z]<\/code>\u8868\u793a\u5339\u914d\u6240\u6709\u5927\u5199\u5b57\u6bcd\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5bf9\u6bd4\u5206\u6790<\/h3>\n<\/p>\n<p><p><strong>\u5217\u8868\u63a8\u5bfc\u5f0f\u3001filter\u51fd\u6570\u3001\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\u4e09\u79cd\u65b9\u6cd5\u5404\u6709\u4f18\u7f3a\u70b9\uff1a<\/p>\n<\/p>\n<ol>\n<li><strong>\u5217\u8868\u63a8\u5bfc\u5f0f<\/strong>\uff1a\u7b80\u6d01\u76f4\u89c2\uff0c\u9002\u5408\u5927\u591a\u6570\u7b80\u5355\u7684\u7b5b\u9009\u64cd\u4f5c\uff0c\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\u3002<\/li>\n<li><strong>filter\u51fd\u6570<\/strong>\uff1a\u529f\u80fd\u5f3a\u5927\u4e14\u901a\u7528\uff0c\u4f46\u4ee3\u7801\u53ef\u8bfb\u6027\u7a0d\u5dee\uff0c\u9002\u5408\u9700\u8981\u590d\u7528\u7b5b\u9009\u51fd\u6570\u7684\u573a\u666f\u3002<\/li>\n<li><strong>\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\uff1a\u5f3a\u5927\u7075\u6d3b\uff0c\u9002\u5408\u590d\u6742\u7684\u5b57\u7b26\u4e32\u5339\u914d\u548c\u7b5b\u9009\u64cd\u4f5c\uff0c\u4f46\u5b66\u4e60\u66f2\u7ebf\u8f83\u9661\u3002<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u7b5b\u9009\u5927\u5199\u5b57\u6bcd\u7684\u9700\u6c42\u53ef\u80fd\u51fa\u73b0\u5728\u5404\u79cd\u573a\u666f\u4e2d\uff0c\u5982\u6570\u636e\u6e05\u6d17\u3001\u6587\u672c\u5904\u7406\u3001\u7528\u6237\u8f93\u5165\u9a8c\u8bc1\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u4f53\u7684\u5e94\u7528\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><h4>1\u3001\u6570\u636e\u6e05\u6d17<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u5305\u542b\u6df7\u5408\u5927\u5c0f\u5199\u5b57\u6bcd\u7684\u6570\u7ec4\u8fdb\u884c\u6e05\u6d17\uff0c\u4ee5\u63d0\u53d6\u7279\u5b9a\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u4ece\u7528\u6237\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e\u4e2d\u63d0\u53d6\u6240\u6709\u5927\u5199\u5b57\u6bcd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def extract_uppercase(data):<\/p>\n<p>    return [char for char in data if char.isupper()]<\/p>\n<h2><strong>\u793a\u4f8b\u6570\u636e<\/strong><\/h2>\n<p>user_data = [&#39;John&#39;, &#39;DOE&#39;, &#39;alice&#39;, &#39;Smith&#39;, &#39;JAMES&#39;]<\/p>\n<p>uppercase_letters = [extract_uppercase(name) for name in user_data]<\/p>\n<p>print(uppercase_letters)  # \u8f93\u51fa: [[&#39;J&#39;], [&#39;D&#39;, &#39;O&#39;, &#39;E&#39;], [], [&#39;S&#39;], [&#39;J&#39;, &#39;A&#39;, &#39;M&#39;, &#39;E&#39;, &#39;S&#39;]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6587\u672c\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u6587\u672c\u5904\u7406\u548c\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff08NLP\uff09\u9886\u57df\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u6587\u672c\u5185\u5bb9\u8fdb\u884c\u7b5b\u9009\uff0c\u4ee5\u63d0\u53d6\u7279\u5b9a\u7684\u5b57\u7b26\u6216\u5355\u8bcd\u3002\u4f8b\u5982\uff0c\u4ece\u4e00\u6bb5\u6587\u672c\u4e2d\u63d0\u53d6\u6240\u6709\u5927\u5199\u5b57\u6bcd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def extract_uppercase_from_text(text):<\/p>\n<p>    return [char for char in text if char.isupper()]<\/p>\n<h2><strong>\u793a\u4f8b\u6587\u672c<\/strong><\/h2>\n<p>text = &quot;Hello World! This is a Test.&quot;<\/p>\n<p>uppercase_letters = extract_uppercase_from_text(text)<\/p>\n<p>print(uppercase_letters)  # \u8f93\u51fa: [&#39;H&#39;, &#39;W&#39;, &#39;T&#39;, &#39;T&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u7528\u6237\u8f93\u5165\u9a8c\u8bc1<\/h4>\n<\/p>\n<p><p>\u5728\u7528\u6237\u8f93\u5165\u9a8c\u8bc1\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u7528\u6237\u8f93\u5165\u7684\u5185\u5bb9\u8fdb\u884c\u7b5b\u9009\uff0c\u4ee5\u786e\u4fdd\u8f93\u5165\u7b26\u5408\u7279\u5b9a\u7684\u683c\u5f0f\u6216\u8981\u6c42\u3002\u4f8b\u5982\uff0c\u9a8c\u8bc1\u5bc6\u7801\u4e2d\u662f\u5426\u5305\u542b\u81f3\u5c11\u4e00\u4e2a\u5927\u5199\u5b57\u6bcd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def cont<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns_uppercase(password):<\/p>\n<p>    return any(char.isupper() for char in password)<\/p>\n<h2><strong>\u793a\u4f8b\u5bc6\u7801<\/strong><\/h2>\n<p>passwords = [&#39;password123&#39;, &#39;Password123&#39;, &#39;PASSWORD123&#39;]<\/p>\n<p>valid_passwords = [pwd for pwd in passwords if contains_uppercase(pwd)]<\/p>\n<p>print(valid_passwords)  # \u8f93\u51fa: [&#39;Password123&#39;, &#39;PASSWORD123&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u7b5b\u9009\u6570\u7ec4\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\u662fPython\u4e2d\u5e38\u89c1\u7684\u6570\u636e\u5904\u7406\u9700\u6c42\uff0c\u53ef\u4ee5\u901a\u8fc7<strong>\u5217\u8868\u63a8\u5bfc\u5f0f\u3001filter\u51fd\u6570\u3001\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong>\u7b49\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u5217\u8868\u63a8\u5bfc\u5f0f\u7b80\u6d01\u76f4\u89c2\uff0c\u9002\u5408\u5927\u591a\u6570\u7b80\u5355\u7684\u7b5b\u9009\u64cd\u4f5c\uff1bfilter\u51fd\u6570\u529f\u80fd\u5f3a\u5927\u4e14\u901a\u7528\uff0c\u9002\u5408\u9700\u8981\u590d\u7528\u7b5b\u9009\u51fd\u6570\u7684\u573a\u666f\uff1b\u6b63\u5219\u8868\u8fbe\u5f0f\u5f3a\u5927\u7075\u6d3b\uff0c\u9002\u5408\u590d\u6742\u7684\u5b57\u7b26\u4e32\u5339\u914d\u548c\u7b5b\u9009\u64cd\u4f5c\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u5e0c\u671b\u8bfb\u8005\u80fd\u591f\u638c\u63e1\u5728Python\u4e2d\u7b5b\u9009\u6570\u7ec4\u4e2d\u5927\u5199\u5b57\u6bcd\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5e76\u80fd\u591f\u7075\u6d3b\u5e94\u7528\u4e8e\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u89e3\u51b3\u5404\u7c7b\u6570\u636e\u5904\u7406\u548c\u6587\u672c\u5904\u7406\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u5927\u5199\u5b57\u6bcd\u7684\u6570\u7ec4\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u7ed3\u5408\u5185\u7f6e\u7684<code>isupper()<\/code>\u65b9\u6cd5\u6765\u7b5b\u9009\u6570\u7ec4\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\u3002\u9996\u5148\uff0c\u5c06\u4e00\u4e2a\u5305\u542b\u4e0d\u540c\u5b57\u7b26\u7684\u6570\u7ec4\u5b9a\u4e49\u4e3a\u4e00\u4e2a\u5217\u8868\uff0c\u7136\u540e\u5229\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u904d\u5386\u8fd9\u4e2a\u5217\u8868\uff0c\u63d0\u53d6\u51fa\u6240\u6709\u5927\u5199\u5b57\u6bcd\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">characters = [&#39;a&#39;, &#39;B&#39;, &#39;c&#39;, &#39;D&#39;, &#39;e&#39;, &#39;F&#39;]\nuppercase_letters = [char for char in characters if char.isupper()]\nprint(uppercase_letters)  # \u8f93\u51fa: [&#39;B&#39;, &#39;D&#39;, &#39;F&#39;]\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u4f7f\u7528filter()\u51fd\u6570\u7b5b\u9009\u5927\u5199\u5b57\u6bcd\uff1f<\/strong><br \/>\u9664\u4e86\u5217\u8868\u63a8\u5bfc\u5f0f\uff0cPython\u7684<code>filter()<\/code>\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u4e8e\u7b5b\u9009\u5927\u5199\u5b57\u6bcd\u3002\u901a\u8fc7\u4f20\u5165\u4e00\u4e2a\u5224\u65ad\u5927\u5199\u5b57\u6bcd\u7684\u51fd\u6570\u548c\u539f\u59cb\u6570\u7ec4\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u8fed\u4ee3\u5668\uff0c\u5305\u542b\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u5143\u7d20\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">characters = [&#39;a&#39;, &#39;B&#39;, &#39;c&#39;, &#39;D&#39;, &#39;e&#39;, &#39;F&#39;]\nuppercase_letters = list(filter(str.isupper, characters))\nprint(uppercase_letters)  # \u8f93\u51fa: [&#39;B&#39;, &#39;D&#39;, &#39;F&#39;]\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5904\u7406\u5305\u542b\u5927\u5199\u5b57\u6bcd\u7684\u5b57\u7b26\u4e32\u800c\u4e0d\u662f\u6570\u7ec4\uff1f<\/strong><br \/>\u5982\u679c\u4f60\u7684\u8f93\u5165\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u800c\u4e0d\u662f\u6570\u7ec4\uff0c\u4f9d\u7136\u53ef\u4ee5\u901a\u8fc7\u7c7b\u4f3c\u7684\u65b9\u6cd5\u8fdb\u884c\u5904\u7406\u3002\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6216<code>filter()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u4ece\u5b57\u7b26\u4e32\u4e2d\u63d0\u53d6\u51fa\u6240\u6709\u5927\u5199\u5b57\u6bcd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">string = &quot;Hello World!&quot;\nuppercase_letters = [char for char in string if char.isupper()]\nprint(uppercase_letters)  # \u8f93\u51fa: [&#39;H&#39;, &#39;W&#39;]\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u7075\u6d3b\u5730\u4ece\u6570\u7ec4\u6216\u5b57\u7b26\u4e32\u4e2d\u7b5b\u9009\u51fa\u5927\u5199\u5b57\u6bcd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u6570\u7ec4\u5982\u4f55\u7b5b\u9009\u5927\u5199\u5b57\u6bcdPython \u5728Python\u4e2d\u7b5b\u9009\u6570\u7ec4\u4e2d\u7684\u5927\u5199\u5b57\u6bcd\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u3001\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1061972,"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\/1061959"}],"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=1061959"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1061959\/revisions"}],"predecessor-version":[{"id":1061976,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1061959\/revisions\/1061976"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1061972"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1061959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1061959"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1061959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}