{"id":1150449,"date":"2025-01-13T17:01:41","date_gmt":"2025-01-13T09:01:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1150449.html"},"modified":"2025-01-13T17:01:44","modified_gmt":"2025-01-13T09:01:44","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e9%9a%8f%e6%9c%ba%e8%b0%83%e7%94%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1150449.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u968f\u673a\u8c03\u7528"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25180941\/c589da48-527a-4c6e-b524-39b3894521e0.webp\" alt=\"python\u4e2d\u5982\u4f55\u968f\u673a\u8c03\u7528\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u968f\u673a\u8c03\u7528\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5185\u7f6e\u7684\u968f\u673a\u6a21\u5757\u3001\u968f\u673a\u9009\u62e9\u51fd\u6570\u3001\u968f\u673a\u751f\u6210\u6570\u503c\u7b49\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002<\/strong> \u901a\u8fc7\u4f7f\u7528\u968f\u673a\u6a21\u5757\u7684\u51fd\u6570\uff0c\u4f60\u53ef\u4ee5\u751f\u6210\u968f\u673a\u6570\u3001\u968f\u673a\u9009\u62e9\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3001\u968f\u673a\u6253\u4e71\u5217\u8868\u987a\u5e8f\u7b49\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u4e2d\u7684\u4e00\u79cd\uff1a<strong>\u4f7f\u7528random.choice()\u51fd\u6570\u6765\u968f\u673a\u9009\u62e9\u5217\u8868\u4e2d\u7684\u5143\u7d20<\/strong>\u3002<\/p>\n<\/p>\n<p><p>random.choice()\u51fd\u6570\u662fPython\u4e2d\u7684\u4e00\u4e2a\u5185\u7f6e\u51fd\u6570\uff0c\u5c5e\u4e8erandom\u6a21\u5757\u3002\u5b83\u7684\u4e3b\u8981\u529f\u80fd\u662f\u4ece\u4e00\u4e2a\u975e\u7a7a\u5e8f\u5217\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5217\u8868<\/strong><\/h2>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<h2><strong>\u4f7f\u7528random.choice()\u51fd\u6570\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u5143\u7d20<\/strong><\/h2>\n<p>random_element = random.choice(my_list)<\/p>\n<p>print(random_element)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86random\u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u4e94\u4e2a\u6574\u6570\u7684\u5217\u8868\u3002\u4f7f\u7528random.choice()\u51fd\u6570\u4ece\u5217\u8868\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\uff0c\u5e76\u5c06\u5176\u6253\u5370\u51fa\u6765\u3002\u6bcf\u6b21\u8fd0\u884c\u8fd9\u4e2a\u4ee3\u7801\uff0c\u8f93\u51fa\u7684\u7ed3\u679c\u4f1a\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u66f4\u8be6\u7ec6\u5730\u63a2\u8ba8Python\u4e2d\u968f\u673a\u8c03\u7528\u7684\u5404\u79cd\u65b9\u6cd5\u548c\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528random\u6a21\u5757\u8fdb\u884c\u968f\u673a\u8c03\u7528<\/h2>\n<\/p>\n<p><h3>1\u3001\u968f\u673a\u751f\u6210\u6570\u503c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528random\u6a21\u5757\u53ef\u4ee5\u751f\u6210\u5404\u79cd\u7c7b\u578b\u7684\u968f\u673a\u6570\uff0c\u5305\u62ec\u6574\u6570\u3001\u6d6e\u70b9\u6570\u7b49\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u51fd\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>random.randint(a, b)<\/strong>\uff1a\u751f\u6210\u4e00\u4e2a\u5728a\u548cb\u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\uff0c\u5305\u542ba\u548cb\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>random_integer = random.randint(1, 10)<\/p>\n<p>print(random_integer)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>random.random()<\/strong>\uff1a\u751f\u6210\u4e00\u4e2a\u57280.0\u52301.0\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570\uff0c\u4e0d\u5305\u542b1.0\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>random_float = random.random()<\/p>\n<p>print(random_float)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>random.uniform(a, b)<\/strong>\uff1a\u751f\u6210\u4e00\u4e2a\u5728a\u548cb\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570\uff0c\u5305\u542ba\u4f46\u4e0d\u5305\u542bb\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>random_uniform = random.uniform(1.0, 10.0)<\/p>\n<p>print(random_uniform)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u968f\u673a\u9009\u62e9\u5143\u7d20<\/h3>\n<\/p>\n<p><p>\u9664\u4e86random.choice()\u51fd\u6570\uff0crandom\u6a21\u5757\u8fd8\u63d0\u4f9b\u4e86\u5176\u4ed6\u4e00\u4e9b\u7528\u4e8e\u968f\u673a\u9009\u62e9\u5143\u7d20\u7684\u51fd\u6570\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>random.choices(population, k)<\/strong>\uff1a\u4ecepopulation\u4e2d\u968f\u673a\u9009\u62e9k\u4e2a\u5143\u7d20\uff0c\u5141\u8bb8\u91cd\u590d\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p>random_elements = random.choices(my_list, k=3)<\/p>\n<p>print(random_elements)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>random.sample(population, k)<\/strong>\uff1a\u4ecepopulation\u4e2d\u968f\u673a\u9009\u62e9k\u4e2a\u5143\u7d20\uff0c\u4e0d\u5141\u8bb8\u91cd\u590d\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p>random_elements = random.sample(my_list, k=3)<\/p>\n<p>print(random_elements)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u968f\u673a\u6253\u4e71\u987a\u5e8f<\/h3>\n<\/p>\n<p><p>random\u6a21\u5757\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u968f\u673a\u6253\u4e71\u5217\u8868\u7684\u987a\u5e8f\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>random.shuffle(x)<\/strong>\uff1a\u5c06x\u4e2d\u7684\u5143\u7d20\u968f\u673a\u6253\u4e71\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>my_list = [1, 2, 3, 4, 5]<\/p>\n<p>random.shuffle(my_list)<\/p>\n<p>print(my_list)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528numpy\u6a21\u5757\u8fdb\u884c\u968f\u673a\u8c03\u7528<\/h2>\n<\/p>\n<p><p>\u9664\u4e86random\u6a21\u5757\uff0cnumpy\u6a21\u5757\u4e5f\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u968f\u673a\u6570\u751f\u6210\u529f\u80fd\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u548c\u77e9\u9635\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><h3>1\u3001\u968f\u673a\u751f\u6210\u6570\u503c<\/h3>\n<\/p>\n<ul>\n<li><strong>numpy.random.randint(low, high, size)<\/strong>\uff1a\u751f\u6210\u4e00\u4e2a\u5728low\u548chigh\u4e4b\u95f4\u7684\u968f\u673a\u6574\u6570\u6570\u7ec4\uff0c\u5305\u542blow\u4f46\u4e0d\u5305\u542bhigh\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>random_array = np.random.randint(1, 10, size=5)<\/p>\n<p>print(random_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>numpy.random.random(size)<\/strong>\uff1a\u751f\u6210\u4e00\u4e2a\u57280.0\u52301.0\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570\u7ec4\uff0c\u4e0d\u5305\u542b1.0\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>random_array = np.random.random(size=5)<\/p>\n<p>print(random_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><strong>numpy.random.uniform(low, high, size)<\/strong>\uff1a\u751f\u6210\u4e00\u4e2a\u5728low\u548chigh\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570\u7ec4\uff0c\u5305\u542blow\u4f46\u4e0d\u5305\u542bhigh\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>random_array = np.random.uniform(1.0, 10.0, size=5)<\/p>\n<p>print(random_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u968f\u673a\u9009\u62e9\u5143\u7d20<\/h3>\n<\/p>\n<p><p>numpy\u6a21\u5757\u63d0\u4f9b\u4e86\u51fd\u6570\u7528\u4e8e\u4ece\u6570\u7ec4\u4e2d\u968f\u673a\u9009\u62e9\u5143\u7d20\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>numpy.random.choice(a, size, replace, p)<\/strong>\uff1a\u4ecea\u4e2d\u968f\u673a\u9009\u62e9size\u4e2a\u5143\u7d20\uff0creplace\u8868\u793a\u662f\u5426\u5141\u8bb8\u91cd\u590d\uff0cp\u8868\u793a\u6bcf\u4e2a\u5143\u7d20\u88ab\u9009\u62e9\u7684\u6982\u7387\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>my_array = np.array([1, 2, 3, 4, 5])<\/p>\n<p>random_elements = np.random.choice(my_array, size=3, replace=False)<\/p>\n<p>print(random_elements)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u968f\u673a\u6253\u4e71\u987a\u5e8f<\/h3>\n<\/p>\n<p><p>numpy\u6a21\u5757\u4e5f\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u968f\u673a\u6253\u4e71\u6570\u7ec4\u7684\u987a\u5e8f\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>numpy.random.shuffle(x)<\/strong>\uff1a\u5c06x\u4e2d\u7684\u5143\u7d20\u968f\u673a\u6253\u4e71\u3002<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>my_array = np.array([1, 2, 3, 4, 5])<\/p>\n<p>np.random.shuffle(my_array)<\/p>\n<p>print(my_array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u5e94\u7528\u573a\u666f<\/h2>\n<\/p>\n<p><h3>1\u3001\u6a21\u62df\u5b9e\u9a8c<\/h3>\n<\/p>\n<p><p>\u968f\u673a\u6570\u751f\u6210\u5728\u6a21\u62df\u5b9e\u9a8c\u4e2d\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u968f\u673a\u6570\u751f\u6210\u5668\u6a21\u62df\u63b7\u9ab0\u5b50\u3001\u629b\u786c\u5e01\u7b49\u5b9e\u9a8c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>def simulate_dice_rolls(num_rolls):<\/p>\n<p>    results = [random.randint(1, 6) for _ in range(num_rolls)]<\/p>\n<p>    return results<\/p>\n<p>dice_rolls = simulate_dice_rolls(10)<\/p>\n<p>print(dice_rolls)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u6570\u636e\u62bd\u6837<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u79d1\u5b66\u4e2d\uff0c\u968f\u673a\u62bd\u6837\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\u3002\u53ef\u4ee5\u4f7f\u7528random\u6a21\u5757\u6216numpy\u6a21\u5757\u4ece\u6570\u636e\u96c6\u4e2d\u968f\u673a\u62bd\u53d6\u6837\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>data = [i for i in range(100)]<\/p>\n<p>sample = random.sample(data, k=10)<\/p>\n<p>print(sample)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u968f\u673a\u6253\u4e71\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u4e2d\uff0c\u968f\u673a\u6253\u4e71\u6570\u636e\u53ef\u4ee5\u5e2e\u52a9\u63d0\u9ad8\u6a21\u578b\u7684\u6cdb\u5316\u80fd\u529b\u3002\u53ef\u4ee5\u4f7f\u7528random.shuffle()\u51fd\u6570\u6216numpy.random.shuffle()\u51fd\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import random<\/p>\n<p>data = [i for i in range(100)]<\/p>\n<p>random.shuffle(data)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86Python\u4e2d\u968f\u673a\u8c03\u7528\u7684\u5404\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528random\u6a21\u5757\u548cnumpy\u6a21\u5757\u3002<strong>\u4f7f\u7528random\u6a21\u5757\u53ef\u4ee5\u751f\u6210\u968f\u673a\u6570\u3001\u968f\u673a\u9009\u62e9\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3001\u968f\u673a\u6253\u4e71\u5217\u8868\u987a\u5e8f\u7b49\uff1b\u4f7f\u7528numpy\u6a21\u5757\u53ef\u4ee5\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u548c\u77e9\u9635\uff0c\u9002\u5408\u6570\u636e\u79d1\u5b66\u548c\u673a\u5668\u5b66\u4e60\u7b49\u9886\u57df\u7684\u5e94\u7528<\/strong>\u3002\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728\u6a21\u62df\u5b9e\u9a8c\u3001\u6570\u636e\u62bd\u6837\u3001\u968f\u673a\u6253\u4e71\u6570\u636e\u7b49\u573a\u666f\u4e2d\u9ad8\u6548\u5730\u5b9e\u73b0\u968f\u673a\u8c03\u7528\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u5728Python\u4e2d\u5b9e\u73b0\u968f\u673a\u8c03\u7528\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u968f\u673a\u9009\u62e9\u529f\u80fd\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>random<\/code>\u6a21\u5757\u6765\u5b9e\u73b0\u968f\u673a\u9009\u62e9\u3002\u5177\u4f53\u6765\u8bf4\uff0c<code>random.choice()<\/code>\u51fd\u6570\u5141\u8bb8\u4ece\u4e00\u4e2a\u5217\u8868\u6216\u5e8f\u5217\u4e2d\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6c34\u679c\u540d\u79f0\u7684\u5217\u8868\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a  <\/p>\n<pre><code class=\"language-python\">import random\n\nfruits = [&#39;apple&#39;, &#39;banana&#39;, &#39;cherry&#39;, &#39;date&#39;]\nrandom_fruit = random.choice(fruits)\nprint(random_fruit)\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u4f60\u6bcf\u6b21\u8fd0\u884c\u7a0b\u5e8f\u65f6\u90fd\u4f1a\u5f97\u5230\u4e00\u4e2a\u968f\u673a\u7684\u6c34\u679c\u540d\u79f0\u3002<\/p>\n<p><strong>Python\u4e2d\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u65b9\u6cd5\u8fdb\u884c\u968f\u673a\u6570\u751f\u6210\uff1f<\/strong><br \/>Python\u7684<code>random<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u591a\u79cd\u751f\u6210\u968f\u673a\u6570\u7684\u65b9\u6cd5\uff0c\u9664\u4e86<code>random.choice()<\/code>\u5916\uff0c\u8fd8\u6709<code>random.randint(a, b)<\/code>\u7528\u4e8e\u751f\u6210\u6307\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6574\u6570\uff0c<code>random.random()<\/code>\u751f\u6210\u4e00\u4e2a0\u52301\u4e4b\u95f4\u7684\u968f\u673a\u6d6e\u70b9\u6570\uff0c<code>random.shuffle()<\/code>\u53ef\u4ee5\u5bf9\u5217\u8868\u8fdb\u884c\u968f\u673a\u6392\u5e8f\u3002\u8fd9\u4e9b\u65b9\u6cd5\u5404\u81ea\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u573a\u666f\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u62e9\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u968f\u673a\u9009\u62e9\u591a\u4e2a\u5143\u7d20\u800c\u4e0d\u662f\u5355\u4e2a\uff1f<\/strong><br \/>\u5982\u679c\u5e0c\u671b\u4ece\u5217\u8868\u4e2d\u968f\u673a\u9009\u62e9\u591a\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528<code>random.sample()<\/code>\u51fd\u6570\u3002\u6b64\u51fd\u6570\u5141\u8bb8\u6307\u5b9a\u9009\u62e9\u7684\u6570\u91cf\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u8981\u4ece\u4e00\u4e2a\u5305\u542b10\u4e2a\u5143\u7d20\u7684\u5217\u8868\u4e2d\u968f\u673a\u9009\u62e93\u4e2a\uff0c\u53ef\u4ee5\u8fd9\u6837\u5b9e\u73b0\uff1a  <\/p>\n<pre><code class=\"language-python\">import random\n\nnumbers = list(range(1, 11))  # \u521b\u5efa\u4e00\u4e2a\u5305\u542b1\u523010\u7684\u5217\u8868\nrandom_numbers = random.sample(numbers, 3)\nprint(random_numbers)\n<\/code><\/pre>\n<p>\u6ce8\u610f\uff0c\u8fd9\u91cc\u9009\u62e9\u7684\u6570\u91cf\u4e0d\u80fd\u8d85\u8fc7\u5217\u8868\u7684\u957f\u5ea6\uff0c\u5426\u5219\u4f1a\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u968f\u673a\u8c03\u7528\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u5185\u7f6e\u7684\u968f\u673a\u6a21\u5757\u3001\u968f\u673a\u9009\u62e9\u51fd\u6570\u3001\u968f\u673a\u751f\u6210\u6570\u503c\u7b49\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002 \u901a\u8fc7\u4f7f\u7528\u968f\u673a\u6a21 [&hellip;]","protected":false},"author":3,"featured_media":1150455,"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\/1150449"}],"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=1150449"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1150449\/revisions"}],"predecessor-version":[{"id":1150457,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1150449\/revisions\/1150457"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1150455"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1150449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1150449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1150449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}