{"id":989903,"date":"2024-12-27T08:15:33","date_gmt":"2024-12-27T00:15:33","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/989903.html"},"modified":"2024-12-27T08:15:35","modified_gmt":"2024-12-27T00:15:35","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%af%bc%e5%8c%85","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/989903.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u5bfc\u5305"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25064859\/6e8646f1-de3a-4103-a2c7-8e13cecf2c59.webp\" alt=\"python\u4e2d\u5982\u4f55\u5bfc\u5305\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u5bfc\u5305\u662f\u4e00\u9879\u57fa\u672c\u800c\u91cd\u8981\u7684\u6280\u80fd\uff0c\u5b83\u5141\u8bb8\u4f60\u4f7f\u7528\u548c\u91cd\u7528\u5176\u4ed6\u6a21\u5757\u548c\u5e93\u4e2d\u7684\u4ee3\u7801\u3002<strong>\u5bfc\u5305\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a\u4f7f\u7528import\u8bed\u53e5\u3001\u4f7f\u7528from&#8230;import\u8bed\u53e5\u3001\u4f7f\u7528as\u5173\u952e\u5b57\u521b\u5efa\u522b\u540d<\/strong>\u3002\u5176\u4e2d\uff0c<strong>\u4f7f\u7528import\u8bed\u53e5<\/strong>\u662f\u6700\u5e38\u89c1\u7684\u5bfc\u5305\u65b9\u6cd5\uff0c\u5141\u8bb8\u4f60\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\uff0c\u7136\u540e\u901a\u8fc7\u6a21\u5757\u540d\u79f0\u8bbf\u95ee\u5176\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><p>\u6bd4\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>import math<\/code>\u5bfc\u5165Python\u7684\u6570\u5b66\u5e93\uff0c\u7136\u540e\u4f7f\u7528<code>math.sqrt(4)<\/code>\u6765\u8ba1\u7b974\u7684\u5e73\u65b9\u6839\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u6a21\u5757\u547d\u540d\u7a7a\u95f4\u4fdd\u6301\u72ec\u7acb\uff0c\u51cf\u5c11\u547d\u540d\u51b2\u7a81\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528import\u8bed\u53e5<\/strong>\u5141\u8bb8\u4f60\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\u5e76\u901a\u8fc7\u6a21\u5757\u540d\u8bbf\u95ee\u5176\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u597d\u5904\u662f\u53ef\u4ee5\u4fdd\u8bc1\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u6a21\u5757\u547d\u540d\u7a7a\u95f4\u7684\u72ec\u7acb\u6027\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecdPython\u4e2d\u5bfc\u5305\u7684\u591a\u79cd\u65b9\u5f0f\u53ca\u5176\u5177\u4f53\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001IMPORT\u8bed\u53e5<\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u662fPython\u4e2d\u6700\u5e38\u89c1\u7684\u5bfc\u5305\u65b9\u5f0f\u3002\u5b83\u5141\u8bb8\u4f60\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\u7684\u5185\u5bb9\uff0c\u5e76\u901a\u8fc7\u6a21\u5757\u540d\u79f0\u6765\u8bbf\u95ee\u5176\u51fd\u6570\u3001\u7c7b\u548c\u53d8\u91cf\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165\u6574\u4e2a\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u5f53\u4f60\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u65f6\uff0c\u4f60\u53ef\u4ee5\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\uff0c\u5e76\u901a\u8fc7\u6a21\u5757\u540d\u6765\u8bbf\u95ee\u5176\u4e2d\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>result = math.sqrt(16)<\/p>\n<p>print(result)  # \u8f93\u51fa: 4.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5bfc\u5165\u4e86<code>math<\/code>\u6a21\u5757\uff0c\u5e76\u4f7f\u7528<code>math.sqrt()<\/code>\u8ba1\u7b9716\u7684\u5e73\u65b9\u6839\u3002\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u6a21\u5757\u7684\u547d\u540d\u7a7a\u95f4\u4fdd\u6301\u72ec\u7acb\uff0c\u51cf\u5c11\u547d\u540d\u51b2\u7a81\u7684\u53ef\u80fd\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u591a\u4e2a\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728\u4e00\u884c\u4e2d\u5bfc\u5165\u591a\u4e2a\u6a21\u5757\uff0c\u7528\u9017\u53f7\u5206\u9694\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os, sys<\/p>\n<p>print(os.name)<\/p>\n<p>print(sys.version)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u7b80\u6d01\u660e\u4e86\uff0c\u4f46\u4e0d\u5efa\u8bae\u5728\u4e00\u884c\u4e2d\u5bfc\u5165\u8fc7\u591a\u6a21\u5757\uff0c\u4ee5\u4fdd\u6301\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u5b50\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e00\u4e9b\u5927\u578b\u7684\u5e93\uff0c\u53ef\u80fd\u5305\u542b\u5b50\u6a21\u5757\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u70b9\u53f7<code>.<\/code>\u6765\u5bfc\u5165\u5b50\u6a21\u5757\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy.random<\/p>\n<p>random_number = numpy.random.rand()<\/p>\n<p>print(random_number)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u5bfc\u5165\u4e86<code>numpy<\/code>\u5e93\u7684<code>random<\/code>\u5b50\u6a21\u5757\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001FROM&#8230;IMPORT\u8bed\u53e5<\/p>\n<\/p>\n<p><p><code>from...import<\/code>\u8bed\u53e5\u5141\u8bb8\u4f60\u4ece\u6a21\u5757\u4e2d\u5bfc\u5165\u7279\u5b9a\u7684\u5c5e\u6027\u6216\u65b9\u6cd5\uff0c\u800c\u65e0\u9700\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\u3002\u8fd9\u5728\u9700\u8981\u9891\u7e41\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u67d0\u4e2a\u529f\u80fd\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165\u7279\u5b9a\u51fd\u6570<\/strong><\/p>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4ece\u6a21\u5757\u4e2d\u5bfc\u5165\u7279\u5b9a\u7684\u51fd\u6570\u6216\u53d8\u91cf\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<p>result = sqrt(25)<\/p>\n<p>print(result)  # \u8f93\u51fa: 5.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u505a\u7684\u597d\u5904\u662f\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>sqrt()<\/code>\uff0c\u800c\u65e0\u9700\u6bcf\u6b21\u90fd\u5199<code>math.sqrt()<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u591a\u4e2a\u51fd\u6570<\/strong><\/p>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728\u4e00\u884c\u4e2d\u5bfc\u5165\u591a\u4e2a\u51fd\u6570\uff0c\u7528\u9017\u53f7\u5206\u9694\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt, ceil<\/p>\n<p>result1 = sqrt(18)<\/p>\n<p>result2 = ceil(4.2)<\/p>\n<p>print(result1, result2)  # \u8f93\u51fa: 4.242640687119285 5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u7b80\u6d01\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u6240\u6709\u5185\u5bb9<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u661f\u53f7<code>*<\/code>\u53ef\u4ee5\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import *<\/p>\n<p>result = sqrt(36)<\/p>\n<p>print(result)  # \u8f93\u51fa: 6.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u800c\uff0c\u8fd9\u79cd\u65b9\u5f0f\u53ef\u80fd\u5bfc\u81f4\u547d\u540d\u51b2\u7a81\uff0c\u5e76\u4e14\u4f7f\u5f97\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u4e0b\u964d\uff0c\u56e0\u6b64\u4e00\u822c\u4e0d\u63a8\u8350\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528AS\u5173\u952e\u5b57\u521b\u5efa\u522b\u540d<\/p>\n<\/p>\n<p><p>\u5728\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>as<\/code>\u5173\u952e\u5b57\u4e3a\u6a21\u5757\u6216\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u522b\u540d\u3002\u8fd9\u6837\u53ef\u4ee5\u7b80\u5316\u4ee3\u7801\uff0c\u5c24\u5176\u662f\u5728\u6a21\u5757\u540d\u79f0\u8f83\u957f\u65f6\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6a21\u5757\u522b\u540d<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u7ed9\u6a21\u5757\u521b\u5efa\u522b\u540d\uff0c\u4f60\u53ef\u4ee5\u7f29\u77ed\u5176\u540d\u79f0\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>array = np.array([1, 2, 3])<\/p>\n<p>print(array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06<code>numpy<\/code>\u6a21\u5757\u91cd\u547d\u540d\u4e3a<code>np<\/code>\uff0c\u8fd9\u6837\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528<code>np<\/code>\u6765\u5f15\u7528<code>numpy<\/code>\uff0c\u4f7f\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u51fd\u6570\u522b\u540d<\/strong><\/p>\n<\/p>\n<p><p>\u540c\u6837\uff0c\u4f60\u53ef\u4ee5\u4e3a\u5bfc\u5165\u7684\u51fd\u6570\u521b\u5efa\u522b\u540d\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt as square_root<\/p>\n<p>result = square_root(49)<\/p>\n<p>print(result)  # \u8f93\u51fa: 7.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>square_root()<\/code>\u6765\u4ee3\u66ff<code>sqrt()<\/code>\uff0c\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u6ce8\u610f\u4e8b\u9879\u4e0e\u6700\u4f73\u5b9e\u8df5<\/p>\n<\/p>\n<p><p>\u5bfc\u5305\u65f6\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff0c\u4ee5\u786e\u4fdd\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u8bfb\u6027\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u907f\u514d\u547d\u540d\u51b2\u7a81<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>import<\/code>\u65f6\uff0c\u5c3d\u91cf\u907f\u514d\u4e0e\u73b0\u6709\u53d8\u91cf\u6216\u51fd\u6570\u540c\u540d\uff0c\u4ee5\u514d\u9020\u6210\u547d\u540d\u51b2\u7a81\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4fdd\u6301\u4ee3\u7801\u7684\u53ef\u8bfb\u6027<\/strong><\/p>\n<\/p>\n<p><p>\u5c3d\u91cf\u5728\u6bcf\u4e00\u884c\u4e2d\u5bfc\u5165\u4e00\u4e2a\u6a21\u5757\u6216\u51fd\u6570\uff0c\u4fdd\u6301\u4ee3\u7801\u7684\u6574\u6d01\u548c\u53ef\u8bfb\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u6a21\u5757\u522b\u540d<\/strong><\/p>\n<\/p>\n<p><p>\u5f53\u6a21\u5757\u540d\u79f0\u8fc7\u957f\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>as<\/code>\u5173\u952e\u5b57\u521b\u5efa\u522b\u540d\uff0c\u7b80\u5316\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u907f\u514d\u4f7f\u7528\u901a\u914d\u7b26\u5bfc\u5165<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>from module import *<\/code>\u867d\u7136\u65b9\u4fbf\uff0c\u4f46\u53ef\u80fd\u5bfc\u81f4\u547d\u540d\u51b2\u7a81\uff0c\u5e76\u4e14\u4f7f\u4ee3\u7801\u53ef\u8bfb\u6027\u4e0b\u964d\u3002\u56e0\u6b64\uff0c\u9664\u975e\u5fc5\u8981\uff0c\u5c3d\u91cf\u907f\u514d\u4f7f\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757\u548c\u5305<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u5bfc\u5165Python\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u5bfc\u5165\u4f60\u81ea\u5df1\u7f16\u5199\u7684\u6a21\u5757\u548c\u5305\u3002\u8fd9\u5728\u5927\u578b\u9879\u76ee\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u4f60\u5c06\u4ee3\u7801\u7ec4\u7ec7\u4e3a\u591a\u4e2a\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5bfc\u5165\u540c\u4e00\u76ee\u5f55\u4e0b\u7684\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u5757\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a<code>mymodule.py<\/code>\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u8fd9\u6837\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mymodule<\/p>\n<p>mymodule.my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u4e0d\u540c\u76ee\u5f55\u4e0b\u7684\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u6a21\u5757\u4f4d\u4e8e\u4e0d\u540c\u76ee\u5f55\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u8c03\u6574<code>sys.path<\/code>\u6216\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>sys.path.append(&#39;\/path\/to\/module_directory&#39;)<\/p>\n<p>import mymodule<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5bfc\u5165\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u5305\u662f\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6a21\u5757\u7684\u76ee\u5f55\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u5305\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>__init__.py<\/code>\u6587\u4ef6\u6765\u5b9a\u4e49\u5305\u3002\u5bfc\u5165\u5305\u65f6\uff0c\u4f7f\u7528\u70b9\u53f7<code>.<\/code>\u8bbf\u95ee\u5b50\u6a21\u5757\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from mypackage import mymodule<\/p>\n<p>mymodule.my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\u5bfc\u5305\u662f\u4e00\u4e2a\u57fa\u672c\u800c\u91cd\u8981\u7684\u6280\u80fd\uff0c\u80fd\u591f\u6781\u5927\u5730\u63d0\u9ad8\u4ee3\u7801\u7684\u91cd\u7528\u6027\u548c\u6a21\u5757\u5316\u3002<strong>\u4f7f\u7528import\u8bed\u53e5\u53ef\u4ee5\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\u3001\u4f7f\u7528from&#8230;import\u8bed\u53e5\u53ef\u4ee5\u5bfc\u5165\u7279\u5b9a\u7684\u51fd\u6570\u6216\u53d8\u91cf\u3001\u4f7f\u7528as\u5173\u952e\u5b57\u53ef\u4ee5\u521b\u5efa\u522b\u540d\u6765\u7b80\u5316\u4ee3\u7801<\/strong>\u3002\u540c\u65f6\uff0c\u826f\u597d\u7684\u5bfc\u5305\u4e60\u60ef\u548c\u7ec4\u7ec7\u7ed3\u6784\u80fd\u8ba9\u9879\u76ee\u66f4\u5177\u53ef\u7ef4\u62a4\u6027\u3002\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0c\u4f60\u5c06\u80fd\u591f\u66f4\u6709\u6548\u5730\u4f7f\u7528Python\u8fdb\u884c\u5f00\u53d1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\uff0c\u5982\u4f55\u5bfc\u5165\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u5bfc\u5165\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\u3002\u6807\u51c6\u5e93\u662fPython\u81ea\u5e26\u7684\u6a21\u5757\uff0c\u4f7f\u7528\u65f6\u53ea\u9700\u5199<code>import \u6a21\u5757\u540d<\/code>\u3002\u800c\u5bf9\u4e8e\u7b2c\u4e09\u65b9\u5e93\uff0c\u786e\u4fdd\u5df2\u901a\u8fc7\u5305\u7ba1\u7406\u5de5\u5177\uff08\u5982pip\uff09\u5b89\u88c5\u540e\uff0c\u4f7f\u7528\u76f8\u540c\u7684\u5bfc\u5165\u65b9\u5f0f\u3002\u4f8b\u5982\uff0c\u5bfc\u5165<code>math<\/code>\u5e93\u53ef\u4ee5\u5199\u6210<code>import math<\/code>\uff0c\u5bfc\u5165\u7b2c\u4e09\u65b9\u5e93\u5982<code>numpy<\/code>\u5219\u4e3a<code>import numpy as np<\/code>\u3002<\/p>\n<p><strong>\u5982\u679c\u6211\u53ea\u60f3\u5bfc\u5165\u5e93\u4e2d\u7684\u7279\u5b9a\u51fd\u6570\u6216\u7c7b\uff0c\u8be5\u600e\u4e48\u505a\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>from<\/code>\u8bed\u53e5\u6765\u5bfc\u5165\u5e93\u4e2d\u7684\u7279\u5b9a\u51fd\u6570\u6216\u7c7b\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u8ba9\u4f60\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e9b\u529f\u80fd\u800c\u4e0d\u9700\u8981\u52a0\u4e0a\u6a21\u5757\u540d\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u53ea\u9700\u8981\u4f7f\u7528<code>sqrt<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5199\u6210<code>from math import sqrt<\/code>\uff0c\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528<code>sqrt(16)<\/code>\u800c\u4e0d\u9700\u8981<code>math.sqrt(16)<\/code>\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5bfc\u5165\u65f6\u53ef\u80fd\u51fa\u73b0\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec<code>ModuleNotFoundError<\/code>\uff0c\u8868\u793a\u627e\u4e0d\u5230\u6307\u5b9a\u7684\u6a21\u5757\u3002\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u529e\u6cd5\u662f\u786e\u8ba4\u8be5\u6a21\u5757\u662f\u5426\u5df2\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip list<\/code>\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5305\uff0c\u6216\u4f7f\u7528<code>pip install \u6a21\u5757\u540d<\/code>\u6765\u5b89\u88c5\u7f3a\u5931\u7684\u6a21\u5757\u3002\u53e6\u5916\uff0c\u786e\u4fddPython\u7684\u73af\u5883\u8bbe\u7f6e\u6b63\u786e\uff0c\u907f\u514d\u56e0\u8def\u5f84\u95ee\u9898\u5bfc\u81f4\u65e0\u6cd5\u5bfc\u5165\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u5bfc\u5305\u662f\u4e00\u9879\u57fa\u672c\u800c\u91cd\u8981\u7684\u6280\u80fd\uff0c\u5b83\u5141\u8bb8\u4f60\u4f7f\u7528\u548c\u91cd\u7528\u5176\u4ed6\u6a21\u5757\u548c\u5e93\u4e2d\u7684\u4ee3\u7801\u3002\u5bfc\u5305\u7684\u65b9\u6cd5\u4e3b\u8981\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a [&hellip;]","protected":false},"author":3,"featured_media":989916,"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\/989903"}],"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=989903"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/989903\/revisions"}],"predecessor-version":[{"id":989920,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/989903\/revisions\/989920"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/989916"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=989903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=989903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=989903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}