{"id":1098247,"date":"2025-01-08T15:19:26","date_gmt":"2025-01-08T07:19:26","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1098247.html"},"modified":"2025-01-08T15:19:29","modified_gmt":"2025-01-08T07:19:29","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8%e5%8c%85%e4%b8%ad%e7%9a%84%e5%87%bd%e6%95%b0-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1098247.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u8c03\u7528\u5305\u4e2d\u7684\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212642\/b9d07244-893c-45b7-9c77-3c7d09988ab4.webp\" alt=\"python\u4e2d\u5982\u4f55\u8c03\u7528\u5305\u4e2d\u7684\u51fd\u6570\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8c03\u7528\u5305\u4e2d\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a\u5bfc\u5165\u5305\u3001\u5bfc\u5165\u6a21\u5757\u3001\u5bfc\u5165\u51fd\u6570\u3001\u4f7f\u7528\u51fd\u6570\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86\u6240\u9700\u7684\u5305\uff0c\u7136\u540e\u901a\u8fc7import\u8bed\u53e5\u5bfc\u5165\u5305\u6216\u6a21\u5757\uff0c\u63a5\u7740\u4f7f\u7528\u70b9\u53f7\u8bed\u6cd5\u6765\u8c03\u7528\u51fd\u6570\u3002<\/strong> \u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u6267\u884c\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5bfc\u5165\u5305<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u8981\u4f7f\u7528\u67d0\u4e2a\u5305\u4e2d\u7684\u51fd\u6570\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165\u8be5\u5305\u3002\u5bfc\u5165\u5305\u53ef\u4ee5\u4f7f\u7528import\u5173\u952e\u5b57\u3002\u4f8b\u5982\uff0c\u8981\u5bfc\u5165numpy\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u65f6\uff0c\u5305\u4e2d\u7684\u6240\u6709\u6a21\u5757\u548c\u51fd\u6570\u90fd\u53ef\u4ee5\u901a\u8fc7np\u6765\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u5bfc\u5165\u6a21\u5757<\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u5305\u4e2d\u5305\u542b\u591a\u4e2a\u6a21\u5757\uff0c\u800c\u4f60\u53ea\u9700\u8981\u4f7f\u7528\u5176\u4e2d\u7684\u67d0\u4e00\u4e2a\u6a21\u5757\u3002\u8fd9\u65f6\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u8be5\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u8981\u5bfc\u5165os\u5305\u4e2d\u7684path\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os.path<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u901a\u8fc7os.path\u6765\u8c03\u7528path\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5bfc\u5165\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u53ea\u9700\u8981\u4f7f\u7528\u67d0\u4e2a\u6a21\u5757\u4e2d\u7684\u67d0\u4e2a\u51fd\u6570\uff0c\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u8be5\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u8981\u5bfc\u5165math\u6a21\u5757\u4e2d\u7684sqrt\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u65f6\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528sqrt\u51fd\u6570\uff0c\u800c\u4e0d\u9700\u8981\u518d\u901a\u8fc7\u6a21\u5757\u540d\u6765\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u4f7f\u7528\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u5bfc\u5165\u5305\u6216\u6a21\u5757\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5176\u4e2d\u7684\u51fd\u6570\u4e86\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u5bfc\u5165\u6574\u4e2a\u5305\u5e76\u8c03\u7528\u51fd\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>array = np.array([1, 2, 3])<\/p>\n<p>print(np.mean(array))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li>\u5bfc\u5165\u6a21\u5757\u5e76\u8c03\u7528\u51fd\u6570<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import os.path<\/p>\n<p>print(os.path.basename(&#39;\/path\/to\/file&#39;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li>\u76f4\u63a5\u5bfc\u5165\u51fd\u6570\u5e76\u8c03\u7528<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<p>print(sqrt(16))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u8be6\u7ec6\u63cf\u8ff0<\/p>\n<\/p>\n<p><p><strong>\u5bfc\u5165\u6574\u4e2a\u5305\u5e76\u8c03\u7528\u51fd\u6570<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u5f53\u4f60\u5bfc\u5165\u6574\u4e2a\u5305\u65f6\uff0c\u4f60\u53ef\u4ee5\u8bbf\u95ee\u5305\u4e2d\u7684\u6240\u6709\u6a21\u5757\u548c\u51fd\u6570\u3002\u6bd4\u5982\uff0c\u5bfc\u5165numpy\u5305\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528np\u6765\u8bbf\u95eenumpy\u4e2d\u7684\u6240\u6709\u5185\u5bb9\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u8ba1\u7b97\u6570\u7ec4\u7684\u5e73\u5747\u503c<\/strong><\/h2>\n<p>mean_value = np.mean(array)<\/p>\n<p>print(f&quot;Mean value: {mean_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86numpy\u5305\uff0c\u7136\u540e\u4f7f\u7528np.array\u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u6570\u7ec4\uff0c\u63a5\u7740\u4f7f\u7528np.mean\u51fd\u6570\u8ba1\u7b97\u4e86\u6570\u7ec4\u7684\u5e73\u5747\u503c\u3002<\/p>\n<\/p>\n<p><p><strong>\u5bfc\u5165\u6a21\u5757\u5e76\u8c03\u7528\u51fd\u6570<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u53ea\u9700\u8981\u4f7f\u7528\u5305\u4e2d\u7684\u67d0\u4e2a\u6a21\u5757\uff0c\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u8be5\u6a21\u5757\u3002\u6bd4\u5982\uff0c\u5bfc\u5165os\u5305\u4e2d\u7684path\u6a21\u5757\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528os.path\u6765\u8bbf\u95eepath\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os.path<\/p>\n<h2><strong>\u83b7\u53d6\u6587\u4ef6\u540d<\/strong><\/h2>\n<p>file_name = os.path.basename(&#39;\/path\/to\/file.txt&#39;)<\/p>\n<p>print(f&quot;File name: {file_name}&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u6587\u4ef6\u6269\u5c55\u540d<\/strong><\/h2>\n<p>file_extension = os.path.splitext(&#39;\/path\/to\/file.txt&#39;)[1]<\/p>\n<p>print(f&quot;File extension: {file_extension}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86os.path\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528os.path.basename\u51fd\u6570\u83b7\u53d6\u4e86\u6587\u4ef6\u540d\uff0c\u63a5\u7740\u4f7f\u7528os.path.splitext\u51fd\u6570\u83b7\u53d6\u4e86\u6587\u4ef6\u7684\u6269\u5c55\u540d\u3002<\/p>\n<\/p>\n<p><p><strong>\u76f4\u63a5\u5bfc\u5165\u51fd\u6570\u5e76\u8c03\u7528<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u53ea\u9700\u8981\u4f7f\u7528\u67d0\u4e2a\u6a21\u5757\u4e2d\u7684\u67d0\u4e2a\u51fd\u6570\uff0c\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u8be5\u51fd\u6570\u3002\u6bd4\u5982\uff0c\u5bfc\u5165math\u6a21\u5757\u4e2d\u7684sqrt\u51fd\u6570\u540e\uff0c\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528sqrt\u51fd\u6570\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<h2><strong>\u8ba1\u7b97\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>result = sqrt(25)<\/p>\n<p>print(f&quot;Square root: {result}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u4ecemath\u6a21\u5757\u4e2d\u5bfc\u5165\u4e86sqrt\u51fd\u6570\uff0c\u7136\u540e\u76f4\u63a5\u8c03\u7528sqrt\u51fd\u6570\u8ba1\u7b97\u4e8625\u7684\u5e73\u65b9\u6839\u3002<\/p>\n<\/p>\n<p><p><strong>\u5bfc\u5165\u5305\u4e2d\u7684\u591a\u4e2a\u51fd\u6570<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u5305\u4e2d\u7684\u591a\u4e2a\u51fd\u6570\u3002\u8fd9\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u9017\u53f7\u5206\u9694\u7684\u65b9\u5f0f\u5bfc\u5165\u591a\u4e2a\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt, pow<\/p>\n<h2><strong>\u8ba1\u7b97\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>square_root = sqrt(16)<\/p>\n<p>print(f&quot;Square root: {square_root}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u5e42<\/strong><\/h2>\n<p>power = pow(2, 3)<\/p>\n<p>print(f&quot;Power: {power}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4ecemath\u6a21\u5757\u4e2d\u5bfc\u5165\u4e86sqrt\u548cpow\u51fd\u6570\uff0c\u7136\u540e\u5206\u522b\u8c03\u7528\u5b83\u4eec\u8ba1\u7b97\u5e73\u65b9\u6839\u548c\u5e42\u3002<\/p>\n<\/p>\n<p><p><strong>\u5bfc\u5165\u5305\u4e2d\u7684\u6240\u6709\u51fd\u6570<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u4f7f\u7528\u5305\u4e2d\u7684\u6240\u6709\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u661f\u53f7\uff08*\uff09\u6765\u5bfc\u5165\u6240\u6709\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import *<\/p>\n<h2><strong>\u8ba1\u7b97\u5e73\u65b9\u6839<\/strong><\/h2>\n<p>square_root = sqrt(36)<\/p>\n<p>print(f&quot;Square root: {square_root}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u5e42<\/strong><\/h2>\n<p>power = pow(3, 4)<\/p>\n<p>print(f&quot;Power: {power}&quot;)<\/p>\n<h2><strong>\u8ba1\u7b97\u5706\u5468\u7387<\/strong><\/h2>\n<p>pi_value = pi<\/p>\n<p>print(f&quot;Pi value: {pi_value}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4ecemath\u6a21\u5757\u4e2d\u5bfc\u5165\u4e86\u6240\u6709\u51fd\u6570\uff0c\u7136\u540e\u5206\u522b\u8c03\u7528sqrt\u3001pow\u548cpi\u51fd\u6570\u8ba1\u7b97\u5e73\u65b9\u6839\u3001\u5e42\u548c\u5706\u5468\u7387\u7684\u503c\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528\u522b\u540d\u5bfc\u5165\u5305\u6216\u6a21\u5757<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u7b80\u5316\u4ee3\u7801\u6216\u907f\u514d\u547d\u540d\u51b2\u7a81\uff0c\u53ef\u4ee5\u4e3a\u5bfc\u5165\u7684\u5305\u6216\u6a21\u5757\u6307\u5b9a\u522b\u540d\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<\/strong><\/h2>\n<p>array = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u8ba1\u7b97\u6570\u7ec4\u7684\u6807\u51c6\u5dee<\/strong><\/h2>\n<p>std_dev = np.std(array)<\/p>\n<p>print(f&quot;Standard Deviation: {std_dev}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4e3anumpy\u5305\u6307\u5b9a\u4e86\u522b\u540dnp\uff0c\u7136\u540e\u4f7f\u7528np\u6765\u8c03\u7528numpy\u4e2d\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p><strong>\u603b\u7ed3<\/strong>\uff1a<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8c03\u7528\u5305\u4e2d\u7684\u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u5bfc\u5165\u5305\u3001\u5bfc\u5165\u6a21\u5757\u6216\u5bfc\u5165\u51fd\u6570\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0\u3002\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u5bfc\u5165\u65b9\u5f0f\uff0c\u53ef\u4ee5\u7b80\u5316\u4ee3\u7801\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002\u65e0\u8bba\u662f\u5bfc\u5165\u6574\u4e2a\u5305\u3001\u5bfc\u5165\u7279\u5b9a\u6a21\u5757\uff0c\u8fd8\u662f\u76f4\u63a5\u5bfc\u5165\u51fd\u6570\uff0c\u90fd\u53ef\u4ee5\u65b9\u4fbf\u5730\u8c03\u7528\u5305\u4e2d\u7684\u51fd\u6570\u6765\u5b8c\u6210\u5404\u79cd\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u5bfc\u5165\u4e00\u4e2a\u5305\u4ee5\u4f7f\u7528\u5176\u51fd\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u5bfc\u5165\u4e00\u4e2a\u5305\u3002\u5bfc\u5165\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u540d\u6765\u8c03\u7528\u5176\u5185\u90e8\u7684\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u4f7f\u7528\u540d\u4e3a<code>my_package<\/code>\u7684\u5305\u4e2d\u7684<code>my_function<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import my_package  \nmy_package.my_function()\n<\/code><\/pre>\n<p>\u5982\u679c\u53ea\u60f3\u5bfc\u5165\u7279\u5b9a\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>from<\/code>\u8bed\u53e5\uff1a  <\/p>\n<pre><code class=\"language-python\">from my_package import my_function  \nmy_function()\n<\/code><\/pre>\n<p><strong>\u5982\u4f55\u5904\u7406\u8c03\u7528\u5305\u51fd\u6570\u65f6\u53ef\u80fd\u51fa\u73b0\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u8c03\u7528\u5305\u4e2d\u7684\u51fd\u6570\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u79cd\u9519\u8bef\uff0c\u6bd4\u5982\u6a21\u5757\u672a\u627e\u5230\u6216\u51fd\u6570\u53c2\u6570\u9519\u8bef\u7b49\u3002\u4e3a\u4e86\u5904\u7406\u8fd9\u4e9b\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528<code>try-except<\/code>\u8bed\u53e5\u6765\u6355\u83b7\u5f02\u5e38\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">try:\n    import my_package\n    my_package.my_function()\nexcept ImportError:\n    print(&quot;\u672a\u627e\u5230\u6307\u5b9a\u7684\u5305\uff0c\u8bf7\u68c0\u67e5\u5305\u540d\u662f\u5426\u6b63\u786e\u3002&quot;)\nexcept TypeError:\n    print(&quot;\u8c03\u7528\u51fd\u6570\u65f6\u53c2\u6570\u9519\u8bef\uff0c\u8bf7\u68c0\u67e5\u53c2\u6570\u7c7b\u578b\u3002&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u53ef\u4ee5\u589e\u5f3a\u4ee3\u7801\u7684\u5065\u58ee\u6027\uff0c\u786e\u4fdd\u5728\u51fa\u73b0\u9519\u8bef\u65f6\u80fd\u591f\u63d0\u4f9b\u53cb\u597d\u7684\u63d0\u793a\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u627e\u67d0\u4e2a\u5305\u4e2d\u53ef\u7528\u7684\u51fd\u6570\u548c\u6a21\u5757\uff1f<\/strong><br \/>\u4e86\u89e3\u5305\u4e2d\u53ef\u7528\u7684\u51fd\u6570\u548c\u6a21\u5757\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u6216\u67e5\u770b\u6587\u6863\u6765\u5b9e\u73b0\u3002\u4f7f\u7528<code>dir()<\/code>\u51fd\u6570\u53ef\u4ee5\u5217\u51fa\u5305\u4e2d\u6240\u6709\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import my_package  \nprint(dir(my_package))\n<\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u67e5\u9605\u8be5\u5305\u7684\u5b98\u65b9\u6587\u6863\u6216\u4f7f\u7528<code>help()<\/code>\u51fd\u6570\u4e5f\u53ef\u4ee5\u83b7\u5f97\u8be6\u7ec6\u4fe1\u606f\uff1a  <\/p>\n<pre><code class=\"language-python\">help(my_package)\n<\/code><\/pre>\n<p>\u8fd9\u4e9b\u65b9\u6cd5\u80fd\u591f\u5e2e\u52a9\u7528\u6237\u5feb\u901f\u4e86\u89e3\u5305\u7684\u529f\u80fd\uff0c\u63d0\u5347\u4f7f\u7528\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8c03\u7528\u5305\u4e2d\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u4e2a\u6b65\u9aa4\uff1a\u5bfc\u5165\u5305\u3001\u5bfc\u5165\u6a21\u5757\u3001\u5bfc\u5165\u51fd\u6570\u3001\u4f7f\u7528\u51fd\u6570\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89 [&hellip;]","protected":false},"author":3,"featured_media":1098257,"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\/1098247"}],"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=1098247"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1098247\/revisions"}],"predecessor-version":[{"id":1098260,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1098247\/revisions\/1098260"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1098257"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1098247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1098247"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1098247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}