{"id":1146801,"date":"2025-01-08T23:19:57","date_gmt":"2025-01-08T15:19:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1146801.html"},"modified":"2025-01-08T23:20:00","modified_gmt":"2025-01-08T15:20:00","slug":"python%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%9c%80%e5%90%8e%e4%b8%80%e4%b8%aa%e5%ad%97%e7%ac%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1146801.html","title":{"rendered":"python\u5982\u4f55\u83b7\u53d6\u5b57\u7b26\u4e32\u6700\u540e\u4e00\u4e2a\u5b57\u7b26"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24182708\/c541eb67-f8bb-4d15-8349-19243fe601d6.webp\" alt=\"python\u5982\u4f55\u83b7\u53d6\u5b57\u7b26\u4e32\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26<\/strong>\uff0c<strong>\u4f7f\u7528\u7d22\u5f15\u3001\u4f7f\u7528\u5207\u7247\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/strong>\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u7684\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528\u7d22\u5f15\u6765\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u7d22\u5f15\u6765\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff1a<\/strong><\/p>\n<p>\u5728Python\u4e2d\uff0c\u5b57\u7b26\u4e32\u662f\u4e00\u4e2a\u5e8f\u5217\u7c7b\u578b\uff0c\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u6765\u8bbf\u95ee\u5b57\u7b26\u4e32\u4e2d\u7684\u5404\u4e2a\u5b57\u7b26\u3002\u6b63\u7d22\u5f15\u4ece0\u5f00\u59cb\uff0c\u8d1f\u7d22\u5f15\u4ece-1\u5f00\u59cb\u3002\u8981\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u53ef\u4ee5\u4f7f\u7528\u8d1f\u7d22\u5f15-1\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;hello&quot;<\/p>\n<p>last_char = my_string[-1]<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u8ba8\u8bba\u5176\u4ed6\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u7d22\u5f15<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528\u7d22\u5f15\u662f\u6700\u76f4\u63a5\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u4f7f\u7528\u8d1f\u7d22\u5f15-1\uff0c\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;hello&quot;<\/p>\n<p>last_char = my_string[-1]<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528\u7d22\u5f15\u4e0d\u4ec5\u7b80\u5355\u76f4\u89c2\uff0c\u800c\u4e14\u6548\u7387\u9ad8\uff0c\u56e0\u4e3a\u5b83\u76f4\u63a5\u8bbf\u95ee\u5b57\u7b26\u4e32\u7684\u7279\u5b9a\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528\u5207\u7247<\/h2>\n<\/p>\n<p><p>\u5207\u7247\u662fPython\u4e2d\u5f3a\u5927\u7684\u529f\u80fd\uff0c\u5141\u8bb8\u4ece\u4e00\u4e2a\u5e8f\u5217\u4e2d\u63d0\u53d6\u5b50\u5e8f\u5217\u3002\u901a\u8fc7\u4f7f\u7528\u5207\u7247\uff0c\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;hello&quot;<\/p>\n<p>last_char = my_string[-1:]<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5207\u7247\u7684\u4f18\u70b9\u662f\u7075\u6d3b\uff0c\u53ef\u4ee5\u7528\u4e8e\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u4efb\u4f55\u90e8\u5206\u3002\u867d\u7136\u5728\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u65f6\uff0c\u5207\u7247\u5e76\u4e0d\u6bd4\u7d22\u5f15\u66f4\u9ad8\u6548\uff0c\u4f46\u5b83\u5728\u5904\u7406\u66f4\u590d\u6742\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/h2>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u51fd\u6570\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5904\u7406\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c<code>str[-1]<\/code>\u662f\u83b7\u53d6\u5b57\u7b26\u4e32\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u7684\u5e38\u7528\u65b9\u6cd5\uff0c\u4f46\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65b9\u6cd5\uff0c\u5982<code>str[len(str)-1]<\/code>\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;hello&quot;<\/p>\n<p>last_char = my_string[len(my_string) - 1]<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u7a0d\u663e\u5197\u957f\uff0c\u4f46\u5728\u67d0\u4e9b\u7279\u6b8a\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u66f4\u6709\u7528\uff0c\u7279\u522b\u662f\u5f53\u6211\u4eec\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u989d\u5916\u7684\u8ba1\u7b97\u6216\u64cd\u4f5c\u65f6\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570<\/h2>\n<\/p>\n<p><p>\u6211\u4eec\u8fd8\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u81ea\u5b9a\u4e49\u51fd\u6570\u6765\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002\u8fd9\u5728\u9700\u8981\u91cd\u590d\u4f7f\u7528\u76f8\u540c\u903b\u8f91\u65f6\u7279\u522b\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def get_last_char(s):<\/p>\n<p>    if s:<\/p>\n<p>        return s[-1]<\/p>\n<p>    return None<\/p>\n<p>my_string = &quot;hello&quot;<\/p>\n<p>last_char = get_last_char(my_string)<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u53ef\u8bfb\u6027\u9ad8\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u51fd\u6570\u4e2d\u6dfb\u52a0\u989d\u5916\u7684\u903b\u8f91\uff0c\u4f8b\u5982\u5904\u7406\u7a7a\u5b57\u7b26\u4e32\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u7ed3\u5408\u5176\u4ed6\u6570\u636e\u7ed3\u6784<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5176\u4ed6\u6570\u636e\u7ed3\u6784\uff08\u5982\u5217\u8868\uff09\u6765\u8fdb\u884c\u64cd\u4f5c\uff0c\u7136\u540e\u518d\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">my_string = &quot;hello&quot;<\/p>\n<p>char_list = list(my_string)<\/p>\n<p>last_char = char_list[-1]<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u4e0d\u5982\u76f4\u63a5\u4f7f\u7528\u7d22\u5f15\u6216\u5207\u7247\u9ad8\u6548\uff0c\u4f46\u5728\u67d0\u4e9b\u9700\u8981\u590d\u6742\u64cd\u4f5c\u7684\u60c5\u51b5\u4e0b\u53ef\u80fd\u4f1a\u66f4\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/h2>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5141\u8bb8\u6211\u4eec\u8fdb\u884c\u590d\u6742\u7684\u6a21\u5f0f\u5339\u914d\u548c\u5b57\u7b26\u4e32\u64cd\u4f5c\u3002\u867d\u7136\u5728\u83b7\u53d6\u5355\u4e2a\u5b57\u7b26\u65f6\u53ef\u80fd\u663e\u5f97\u6709\u4e9b\u201c\u6740\u9e21\u7528\u725b\u5200\u201d\uff0c\u4f46\u5728\u5904\u7406\u66f4\u590d\u6742\u7684\u5b57\u7b26\u4e32\u64cd\u4f5c\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<p>my_string = &quot;hello&quot;<\/p>\n<p>match = re.search(r&#39;.$&#39;, my_string)<\/p>\n<p>last_char = match.group() if match else None<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b63\u5219\u8868\u8fbe\u5f0f\u5728\u5904\u7406\u590d\u6742\u6a21\u5f0f\u5339\u914d\u65f6\u975e\u5e38\u6709\u7528\uff0c\u4f46\u5728\u83b7\u53d6\u7b80\u5355\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u65f6\u53ef\u80fd\u663e\u5f97\u8fc7\u4e8e\u590d\u6742\u3002<\/p>\n<\/p>\n<p><h2>\u4e03\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u6765\u5904\u7406\u5b57\u7b26\u4e32\u64cd\u4f5c\u3002\u867d\u7136Python\u5185\u7f6e\u7684\u65b9\u6cd5\u5df2\u7ecf\u975e\u5e38\u5f3a\u5927\uff0c\u4f46\u7b2c\u4e09\u65b9\u5e93\u53ef\u80fd\u63d0\u4f9b\u989d\u5916\u7684\u529f\u80fd\u548c\u66f4\u9ad8\u6548\u7684\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c<code>numpy<\/code>\u5e93\u867d\u7136\u4e3b\u8981\u7528\u4e8e\u6570\u503c\u8ba1\u7b97\uff0c\u4f46\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5b57\u7b26\u4e32\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>my_string = np.array(list(&quot;hello&quot;))<\/p>\n<p>last_char = my_string[-1]<\/p>\n<p>print(last_char)  # \u8f93\u51fa: o<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u901a\u5e38\u4f1a\u5f15\u5165\u989d\u5916\u7684\u4f9d\u8d56\uff0c\u56e0\u6b64\u5728\u9009\u62e9\u65b9\u6cd5\u65f6\u5e94\u6743\u8861\u5229\u5f0a\u3002<\/p>\n<\/p>\n<p><h2>\u516b\u3001\u6027\u80fd\u6bd4\u8f83<\/h2>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u4e0d\u4ec5\u53d6\u51b3\u4e8e\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\uff0c\u8fd8\u53d6\u51b3\u4e8e\u6027\u80fd\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u57fa\u51c6\u6d4b\u8bd5\u6765\u6bd4\u8f83\u4e0d\u540c\u65b9\u6cd5\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import timeit<\/p>\n<p>my_string = &quot;hello&quot;<\/p>\n<h2><strong>\u4f7f\u7528\u7d22\u5f15<\/strong><\/h2>\n<p>index_time = timeit.timeit(lambda: my_string[-1], number=1000000)<\/p>\n<h2><strong>\u4f7f\u7528\u5207\u7247<\/strong><\/h2>\n<p>slice_time = timeit.timeit(lambda: my_string[-1:], number=1000000)<\/p>\n<h2><strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570<\/strong><\/h2>\n<p>len_time = timeit.timeit(lambda: my_string[len(my_string) - 1], number=1000000)<\/p>\n<p>print(f&quot;Index Time: {index_time:.6f} seconds&quot;)<\/p>\n<p>print(f&quot;Slice Time: {slice_time:.6f} seconds&quot;)<\/p>\n<p>print(f&quot;Len Time: {len_time:.6f} seconds&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u76f4\u63a5\u4f7f\u7528\u7d22\u5f15\u7684\u65b9\u6cd5\u6027\u80fd\u6700\u597d\uff0c\u56e0\u4e3a\u5b83\u662f\u6700\u76f4\u63a5\u7684\u8bbf\u95ee\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><h2>\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6709\u591a\u79cd\u65b9\u6cd5\uff0c<strong>\u4f7f\u7528\u7d22\u5f15\u3001\u4f7f\u7528\u5207\u7247\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3001\u4f7f\u7528\u81ea\u5b9a\u4e49\u51fd\u6570\u3001\u7ed3\u5408\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u3001\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/strong>\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\u3002\u5bf9\u4e8e\u5927\u591a\u6570\u60c5\u51b5\uff0c\u4f7f\u7528\u7d22\u5f15\u662f\u6700\u7b80\u5355\u9ad8\u6548\u7684\u65b9\u6cd5\uff0c\u4f46\u5728\u67d0\u4e9b\u7279\u5b9a\u573a\u666f\u4e0b\uff0c\u5176\u4ed6\u65b9\u6cd5\u53ef\u80fd\u66f4\u4e3a\u5408\u9002\u3002\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6027\u80fd\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u63d0\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u8d1f\u7d22\u5f15\u6765\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002\u8d1f\u7d22\u5f15\u4ece\u5b57\u7b26\u4e32\u7684\u672b\u5c3e\u5f00\u59cb\u8ba1\u6570\uff0c\u56e0\u6b64\u4f7f\u7528<code>-1<\/code>\u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u5982\u679c\u6709\u5b57\u7b26\u4e32<code>my_string = &quot;Hello&quot;<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7<code>last_char = my_string[-1]<\/code>\u6765\u83b7\u5f97\u6700\u540e\u4e00\u4e2a\u5b57\u7b26<code>&#39;o&#39;<\/code>\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u7684\u5207\u7247\u529f\u80fd\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u6709\u54ea\u4e9b\u4f18\u52bf\uff1f<\/strong><br \/>\u5207\u7247\u662fPython\u4e2d\u975e\u5e38\u5f3a\u5927\u7684\u7279\u6027\uff0c\u53ef\u4ee5\u7528\u6765\u7b80\u5316\u5b57\u7b26\u4e32\u64cd\u4f5c\u3002\u901a\u8fc7\u4f7f\u7528<code>my_string[-1:]<\/code>\uff0c\u53ef\u4ee5\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u4e14\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u76f4\u89c2\uff0c\u8fd8\u53ef\u4ee5\u907f\u514d\u5728\u5176\u4ed6\u60c5\u51b5\u4e0b\u56e0\u7d22\u5f15\u9519\u8bef\u800c\u5bfc\u81f4\u7684\u5f02\u5e38\u3002<\/p>\n<p><strong>\u5982\u679c\u5b57\u7b26\u4e32\u4e3a\u7a7a\uff0c\u5982\u4f55\u5b89\u5168\u5730\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff1f<\/strong><br \/>\u5728\u5904\u7406\u5b57\u7b26\u4e32\u65f6\uff0c\u786e\u4fdd\u5b57\u7b26\u4e32\u4e0d\u4e3a\u7a7a\u662f\u5f88\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u5728\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u4e4b\u524d\uff0c\u5148\u68c0\u67e5\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>if len(my_string) &gt; 0:<\/code>\u5224\u65ad\u5b57\u7b26\u4e32\u662f\u5426\u4e3a\u7a7a\u3002\u82e5\u4e0d\u4e3a\u7a7a\uff0c\u5219\u53ef\u4ee5\u5b89\u5168\u5730\u4f7f\u7528<code>my_string[-1]<\/code>\u6765\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002\u8fd9\u6837\u53ef\u4ee5\u6709\u6548\u907f\u514d\u56e0\u7a7a\u5b57\u7b26\u4e32\u800c\u5f15\u53d1\u7684<code>IndexError<\/code>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u83b7\u53d6\u5b57\u7b26\u4e32\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u4f7f\u7528\u7d22\u5f15\u3001\u4f7f\u7528\u5207\u7247\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176 [&hellip;]","protected":false},"author":3,"featured_media":1146809,"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\/1146801"}],"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=1146801"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1146801\/revisions"}],"predecessor-version":[{"id":1146811,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1146801\/revisions\/1146811"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1146809"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1146801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1146801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1146801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}