{"id":1126024,"date":"2025-01-08T19:57:11","date_gmt":"2025-01-08T11:57:11","guid":{"rendered":""},"modified":"2025-01-08T19:57:14","modified_gmt":"2025-01-08T11:57:14","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e6%9f%a5%e6%89%be%e5%88%97%e8%a1%a8%e4%b8%ad%e7%9a%84%e6%9c%80%e5%a4%a7%e5%80%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1126024.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u67e5\u627e\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090502\/f84e30e0-6c98-4c0a-bb96-47f09a536b64.webp\" alt=\"python\u4e2d\u5982\u4f55\u67e5\u627e\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u67e5\u627e\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u3001\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5217\u8868\u3001\u4f7f\u7528\u6392\u5e8f\u65b9\u6cd5\u3002<\/strong> \u5176\u4e2d\uff0c<strong>\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()<\/strong> \u662f\u6700\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u6cd5\uff0c\u53ea\u9700\u8c03\u7528\u4e00\u6b21\u51fd\u6570\u5373\u53ef\u8fd4\u56de\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u8fd9\u4e00\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u5185\u7f6e\u7684 <code>max()<\/code> \u51fd\u6570\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u3001\u7b80\u4fbf\u5730\u627e\u5230\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002\u8fd9\u4e2a\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff08\u5982\u5217\u8868\uff09\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u5176\u4e2d\u7684\u6700\u5927\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [3, 5, 7, 2, 8]<\/p>\n<p>max_value = max(numbers)<\/p>\n<p>print(max_value)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5176\u4ed6\u65b9\u6cd5\u548c\u4e00\u4e9b\u76f8\u5173\u7684\u9ad8\u7ea7\u7528\u6cd5\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()<\/h2>\n<\/p>\n<p><h3>1.1 \u57fa\u672c\u7528\u6cd5<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u7684 <code>max()<\/code> \u51fd\u6570\u662f\u67e5\u627e\u5217\u8868\u6700\u5927\u503c\u7684\u6700\u5feb\u65b9\u6cd5\u3002\u5b83\u4e0d\u4ec5\u652f\u6301\u5217\u8868\uff0c\u8fd8\u652f\u6301\u4efb\u4f55\u53ef\u8fed\u4ee3\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [3, 5, 7, 2, 8]<\/p>\n<p>max_value = max(numbers)<\/p>\n<p>print(max_value)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>1.2 \u5e26\u5173\u952e\u5b57\u53c2\u6570\u7684\u7528\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u4e00\u4e9b\u9ad8\u7ea7\u5e94\u7528\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u67e5\u627e\u57fa\u4e8e\u67d0\u4e9b\u6807\u51c6\u7684\u6700\u5927\u503c\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528 <code>max()<\/code> \u51fd\u6570\u7684 <code>key<\/code> \u53c2\u6570\u3002\u4f8b\u5982\uff0c\u627e\u5230\u4e00\u4e2a\u5217\u8868\u4e2d\u957f\u5ea6\u6700\u957f\u7684\u5b57\u7b26\u4e32\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">words = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;date&quot;]<\/p>\n<p>longest_word = max(words, key=len)<\/p>\n<p>print(longest_word)  # \u8f93\u51fa banana<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5217\u8868<\/h2>\n<\/p>\n<p><h3>2.1 \u4f7f\u7528for\u5faa\u73af<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4e0d\u60f3\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u904d\u5386\u5217\u8868\u6765\u627e\u5230\u6700\u5927\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u4ee3\u7801\u7a0d\u957f\uff0c\u4f46\u903b\u8f91\u6e05\u6670\uff0c\u9002\u7528\u4e8e\u7406\u89e3\u7b97\u6cd5\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [3, 5, 7, 2, 8]<\/p>\n<p>max_value = numbers[0]<\/p>\n<p>for num in numbers:<\/p>\n<p>    if num &gt; max_value:<\/p>\n<p>        max_value = num<\/p>\n<p>print(max_value)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2.2 \u4f7f\u7528while\u5faa\u73af<\/h3>\n<\/p>\n<p><p>\u7c7b\u4f3c\u5730\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>while<\/code> \u5faa\u73af\u6765\u5b9e\u73b0\u76f8\u540c\u7684\u529f\u80fd\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [3, 5, 7, 2, 8]<\/p>\n<p>max_value = numbers[0]<\/p>\n<p>i = 1<\/p>\n<p>while i &lt; len(numbers):<\/p>\n<p>    if numbers[i] &gt; max_value:<\/p>\n<p>        max_value = numbers[i]<\/p>\n<p>    i += 1<\/p>\n<p>print(max_value)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528\u6392\u5e8f\u65b9\u6cd5<\/h2>\n<\/p>\n<p><h3>3.1 \u4f7f\u7528\u5185\u7f6e\u7684sort()\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u5148\u5bf9\u5217\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u53d6\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u4f5c\u4e3a\u6700\u5927\u503c\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u6548\u7387\u76f8\u5bf9\u8f83\u4f4e\uff0c\u4f46\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [3, 5, 7, 2, 8]<\/p>\n<p>numbers.sort()<\/p>\n<p>max_value = numbers[-1]<\/p>\n<p>print(max_value)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3.2 \u4f7f\u7528sorted()\u51fd\u6570<\/h3>\n<\/p>\n<p><p><code>sorted()<\/code> \u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u6392\u5e8f\u5217\u8868\uff0c\u4e0d\u4f1a\u4fee\u6539\u539f\u5217\u8868\u3002\u9002\u7528\u4e8e\u9700\u8981\u4fdd\u6301\u539f\u5217\u8868\u4e0d\u53d8\u7684\u60c5\u51b5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [3, 5, 7, 2, 8]<\/p>\n<p>sorted_numbers = sorted(numbers)<\/p>\n<p>max_value = sorted_numbers[-1]<\/p>\n<p>print(max_value)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u5728\u590d\u6742\u6570\u636e\u7ed3\u6784\u4e2d\u67e5\u627e\u6700\u5927\u503c<\/h2>\n<\/p>\n<p><h3>4.1 \u67e5\u627e\u5d4c\u5957\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c<\/h3>\n<\/p>\n<p><p>\u5728\u5d4c\u5957\u5217\u8868\u4e2d\u67e5\u627e\u6700\u5927\u503c\u9700\u8981\u904d\u5386\u6bcf\u4e2a\u5b50\u5217\u8868\uff0c\u5e76\u8bb0\u5f55\u5176\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">nested_list = [[3, 5, 7], [2, 8, 1], [6, 4, 9]]<\/p>\n<p>max_value = float(&#39;-inf&#39;)<\/p>\n<p>for sublist in nested_list:<\/p>\n<p>    sublist_max = max(sublist)<\/p>\n<p>    if sublist_max &gt; max_value:<\/p>\n<p>        max_value = sublist_max<\/p>\n<p>print(max_value)  # \u8f93\u51fa 9<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.2 \u67e5\u627e\u5217\u8868\u4e2d\u5b57\u5178\u7684\u6700\u5927\u503c<\/h3>\n<\/p>\n<p><p>\u5728\u5217\u8868\u4e2d\u67e5\u627e\u5b57\u5178\u67d0\u4e2a\u952e\u7684\u6700\u5927\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>max()<\/code> \u51fd\u6570\u7684 <code>key<\/code> \u53c2\u6570\u3002\u4f8b\u5982\uff0c\u627e\u5230\u5b57\u5178\u5217\u8868\u4e2d\u5e74\u9f84\u6700\u5927\u7684\u4eba\u7684\u540d\u5b57\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">people = [{&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 30}, {&#39;name&#39;: &#39;Bob&#39;, &#39;age&#39;: 25}, {&#39;name&#39;: &#39;Charlie&#39;, &#39;age&#39;: 35}]<\/p>\n<p>oldest_person = max(people, key=lambda x: x[&#39;age&#39;])<\/p>\n<p>print(oldest_person[&#39;name&#39;])  # \u8f93\u51fa Charlie<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u5728NumPy\u6570\u7ec4\u4e2d\u67e5\u627e\u6700\u5927\u503c<\/h2>\n<\/p>\n<p><h3>5.1 \u4f7f\u7528NumPy\u7684amax()\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 <code>numpy.amax()<\/code> \u67e5\u627e\u6570\u7ec4\u4e2d\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>numbers = np.array([3, 5, 7, 2, 8])<\/p>\n<p>max_value = np.amax(numbers)<\/p>\n<p>print(max_value)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>5.2 \u67e5\u627e\u591a\u7ef4\u6570\u7ec4\u7684\u6700\u5927\u503c<\/h3>\n<\/p>\n<p><p>NumPy\u8fd8\u652f\u6301\u5728\u591a\u7ef4\u6570\u7ec4\u4e2d\u67e5\u627e\u6700\u5927\u503c\uff0c\u53ef\u4ee5\u6307\u5b9a\u8f74\uff08axis\uff09\u6765\u67e5\u627e\u7279\u5b9a\u7ef4\u5ea6\u4e0a\u7684\u6700\u5927\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>numbers = np.array([[3, 5, 7], [2, 8, 1], [6, 4, 9]])<\/p>\n<p>max_value = np.amax(numbers)<\/p>\n<p>print(max_value)  # \u8f93\u51fa 9<\/p>\n<p>max_value_axis0 = np.amax(numbers, axis=0)<\/p>\n<p>print(max_value_axis0)  # \u8f93\u51fa [6 8 9]<\/p>\n<p>max_value_axis1 = np.amax(numbers, axis=1)<\/p>\n<p>print(max_value_axis1)  # \u8f93\u51fa [7 8 9]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u516d\u3001\u6027\u80fd\u6bd4\u8f83<\/h2>\n<\/p>\n<p><h3>6.1 \u5185\u7f6e\u51fd\u6570max()\u7684\u6027\u80fd<\/h3>\n<\/p>\n<p><p><code>max()<\/code> \u51fd\u6570\u662f\u67e5\u627e\u5217\u8868\u6700\u5927\u503c\u7684\u6700\u5feb\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u662f\u7528C\u8bed\u8a00\u5b9e\u73b0\u7684\uff0c\u7ecf\u8fc7\u9ad8\u5ea6\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import timeit<\/p>\n<p>numbers = list(range(1000000))<\/p>\n<p>print(timeit.timeit(&quot;max(numbers)&quot;, globals=globals(), number=1000))  # \u8f93\u51fa\u65f6\u95f4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>6.2 \u81ea\u5b9a\u4e49\u5faa\u73af\u7684\u6027\u80fd<\/h3>\n<\/p>\n<p><p>\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u81ea\u5b9a\u4e49\u5faa\u73af\u7684\u65b9\u6cd5\u7a0d\u6162\uff0c\u4f46\u4ecd\u7136\u5728\u53ef\u63a5\u53d7\u8303\u56f4\u5185\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def find_max(numbers):<\/p>\n<p>    max_value = numbers[0]<\/p>\n<p>    for num in numbers:<\/p>\n<p>        if num &gt; max_value:<\/p>\n<p>            max_value = num<\/p>\n<p>    return max_value<\/p>\n<p>print(timeit.timeit(&quot;find_max(numbers)&quot;, globals=globals(), number=1000))  # \u8f93\u51fa\u65f6\u95f4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>6.3 \u6392\u5e8f\u65b9\u6cd5\u7684\u6027\u80fd<\/h3>\n<\/p>\n<p><p>\u6392\u5e8f\u65b9\u6cd5\u7684\u6027\u80fd\u6700\u5dee\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(timeit.timeit(&quot;sorted(numbers)[-1]&quot;, globals=globals(), number=1000))  # \u8f93\u51fa\u65f6\u95f4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e03\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\u67e5\u627e\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5176\u4e2d\u6700\u7b80\u5355\u548c\u9ad8\u6548\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5185\u7f6e\u7684 <code>max()<\/code> \u51fd\u6570\u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5982\u5d4c\u5957\u5217\u8868\u6216\u5305\u542b\u5b57\u5178\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u7ed3\u5408 <code>max()<\/code> \u51fd\u6570\u7684 <code>key<\/code> \u53c2\u6570\u6216\u4f7f\u7528\u5faa\u73af\u904d\u5386\u7684\u65b9\u6cd5\u3002\u6b64\u5916\uff0c\u5bf9\u4e8e\u5927\u89c4\u6a21\u6570\u636e\uff0cNumPy\u5e93\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u5e94\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u6570\u636e\u89c4\u6a21\u8fdb\u884c\u6743\u8861\uff0c\u786e\u4fdd\u4ee3\u7801\u65e2\u7b80\u6d01\u53c8\u9ad8\u6548\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u67e5\u627e\u5217\u8868\u7684\u6700\u5927\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>max()<\/code>\u51fd\u6570\u6765\u67e5\u627e\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u3002\u8be5\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u5176\u4e2d\u7684\u6700\u5927\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5217\u8868<code>numbers = [3, 1, 4, 1, 5, 9]<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7<code>max(numbers)<\/code>\u6765\u83b7\u53d6\u6700\u5927\u503c9\u3002<\/p>\n<p><strong>\u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff0c\u4f7f\u7528max()\u51fd\u6570\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5982\u679c\u4f60\u5c1d\u8bd5\u5728\u4e00\u4e2a\u7a7a\u5217\u8868\u4e0a\u4f7f\u7528<code>max()<\/code>\u51fd\u6570\uff0cPython\u5c06\u629b\u51fa\u4e00\u4e2a<code>ValueError<\/code>\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u5728\u8c03\u7528<code>max()<\/code>\u4e4b\u524d\u68c0\u67e5\u5217\u8868\u662f\u5426\u4e3a\u7a7a\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5<code>if numbers:<\/code>\u6765\u786e\u8ba4\u5217\u8868\u4e0d\u4e3a\u7a7a\uff0c\u7136\u540e\u518d\u8c03\u7528<code>max()<\/code>\u3002<\/p>\n<p><strong>\u9664\u4e86max()\u51fd\u6570\uff0c\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\u53ef\u4ee5\u67e5\u627e\u5217\u8868\u7684\u6700\u5927\u503c\u5417\uff1f<\/strong><br \/>\u5f53\u7136\uff0c\u9664\u4e86\u4f7f\u7528<code>max()<\/code>\u51fd\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5217\u8868\u6765\u624b\u52a8\u67e5\u627e\u6700\u5927\u503c\u3002\u53ef\u4ee5\u521d\u59cb\u5316\u4e00\u4e2a\u53d8\u91cf\u4e3a\u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u7136\u540e\u9010\u4e00\u6bd4\u8f83\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u66f4\u65b0\u8fd9\u4e2a\u53d8\u91cf\u4ee5\u4fdd\u6301\u6700\u5927\u503c\u3002\u8fd9\u79cd\u65b9\u6cd5\u867d\u7136\u7b80\u5355\uff0c\u4f46\u5728\u6027\u80fd\u4e0a\u4e0d\u5982\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u9ad8\u6548\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5305\u542b\u91cd\u590d\u6700\u5927\u503c\u7684\u5217\u8868\uff1f<\/strong><br \/>\u5982\u679c\u5217\u8868\u4e2d\u5b58\u5728\u591a\u4e2a\u76f8\u540c\u7684\u6700\u5927\u503c\uff0c<code>max()<\/code>\u51fd\u6570\u4ecd\u7136\u4f1a\u8fd4\u56de\u90a3\u4e2a\u6700\u5927\u503c\uff0c\u4f46\u5982\u679c\u9700\u8981\u627e\u51fa\u6240\u6709\u6700\u5927\u503c\u7684\u7d22\u5f15\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u7ed3\u5408<code>max()<\/code>\u51fd\u6570\u3002\u793a\u4f8b\u4ee3\u7801\u53ef\u4ee5\u662f<code>[i for i, value in enumerate(numbers) if value == max(numbers)]<\/code>\uff0c\u8fd9\u5c06\u8fd4\u56de\u6240\u6709\u6700\u5927\u503c\u5728\u5217\u8868\u4e2d\u7684\u7d22\u5f15\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u67e5\u627e\u5217\u8868\u4e2d\u7684\u6700\u5927\u503c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u5185\u7f6e\u51fd\u6570max()\u3001\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5217\u8868\u3001\u4f7f\u7528\u6392\u5e8f\u65b9\u6cd5 [&hellip;]","protected":false},"author":3,"featured_media":1126031,"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\/1126024"}],"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=1126024"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126024\/revisions"}],"predecessor-version":[{"id":1126034,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1126024\/revisions\/1126034"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1126031"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1126024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1126024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1126024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}