{"id":1098208,"date":"2025-01-08T15:19:06","date_gmt":"2025-01-08T07:19:06","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1098208.html"},"modified":"2025-01-08T15:19:09","modified_gmt":"2025-01-08T07:19:09","slug":"python%e5%a6%82%e4%bd%95%e6%98%be%e7%a4%bapi%e5%92%8ce%e7%9a%84%e5%80%bc-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1098208.html","title":{"rendered":"python\u5982\u4f55\u663e\u793api\u548ce\u7684\u503c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212631\/7c37091d-7a06-441c-a714-25f2a2656caf.webp\" alt=\"python\u5982\u4f55\u663e\u793api\u548ce\u7684\u503c\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u663e\u793aPi\u548ce\u7684\u503c<\/strong><\/p>\n<\/p>\n<p><p><strong>\u5728Python\u4e2d\u663e\u793aPi\u548ce\u7684\u503c\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528math\u6a21\u5757\u3001sympy\u5e93\u3001numpy\u5e93\u7b49\u3002<\/strong>\u5176\u4e2d\uff0cmath\u6a21\u5757\u662f\u6700\u5e38\u7528\u7684\uff0c\u56e0\u4e3a\u5b83\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u4e0d\u9700\u8981\u989d\u5916\u5b89\u88c5\u3002<strong>\u4f7f\u7528math\u6a21\u5757\u3001\u4f7f\u7528sympy\u5e93\u3001\u4f7f\u7528numpy\u5e93<\/strong>\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u80fd\u65b9\u4fbf\u5730\u83b7\u53d6\u5e76\u663e\u793aPi\u548ce\u7684\u503c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528math\u6a21\u5757<\/h3>\n<\/p>\n<p><p>Python\u7684math\u6a21\u5757\u63d0\u4f9b\u4e86\u8bb8\u591a\u6570\u5b66\u51fd\u6570\u548c\u5e38\u91cf\uff0c\u5176\u4e2d\u5305\u62ecPi\u548ce\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5bfc\u5165math\u6a21\u5757\u5e76\u76f4\u63a5\u8bbf\u95ee\u8fd9\u4e9b\u5e38\u91cf\u6765\u663e\u793a\u5b83\u4eec\u7684\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u663e\u793aPi\u7684\u503c<\/strong><\/h2>\n<p>pi_value = math.pi<\/p>\n<p>print(&quot;Pi\u7684\u503c\u662f\uff1a&quot;, pi_value)<\/p>\n<h2><strong>\u663e\u793ae\u7684\u503c<\/strong><\/h2>\n<p>e_value = math.e<\/p>\n<p>print(&quot;e\u7684\u503c\u662f\uff1a&quot;, e_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86math\u6a21\u5757\uff0c\u7136\u540e\u901a\u8fc7<code>math.pi<\/code>\u548c<code>math.e<\/code>\u5206\u522b\u83b7\u53d6\u4e86Pi\u548ce\u7684\u503c\u3002\u6700\u540e\uff0c\u6211\u4eec\u4f7f\u7528print\u51fd\u6570\u5c06\u5b83\u4eec\u663e\u793a\u51fa\u6765\u3002<strong>math\u6a21\u5757\u662fPython\u6807\u51c6\u5e93\u7684\u4e00\u90e8\u5206\uff0c\u4e0d\u9700\u8981\u989d\u5916\u5b89\u88c5\uff0c\u4f7f\u7528\u8d77\u6765\u975e\u5e38\u65b9\u4fbf\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528sympy\u5e93<\/h3>\n<\/p>\n<p><p>Sympy\u662fPython\u7684\u4e00\u4e2a\u7b26\u53f7\u6570\u5b66\u5e93\uff0c\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u5b66\u529f\u80fd\uff0c\u5305\u62ec\u7b26\u53f7\u8fd0\u7b97\u3001\u5fae\u79ef\u5206\u3001\u7ebf\u6027\u4ee3\u6570\u7b49\u3002Sympy\u5e93\u4e5f\u5305\u542b\u4e86Pi\u548ce\u7684\u5e38\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5bfc\u5165sympy\u5e93\u5e76\u8bbf\u95ee\u8fd9\u4e9b\u5e38\u91cf\u6765\u663e\u793a\u5b83\u4eec\u7684\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sympy as sp<\/p>\n<h2><strong>\u663e\u793aPi\u7684\u503c<\/strong><\/h2>\n<p>pi_value = sp.pi<\/p>\n<p>print(&quot;Pi\u7684\u503c\u662f\uff1a&quot;, pi_value)<\/p>\n<h2><strong>\u663e\u793ae\u7684\u503c<\/strong><\/h2>\n<p>e_value = sp.E<\/p>\n<p>print(&quot;e\u7684\u503c\u662f\uff1a&quot;, e_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86sympy\u5e93\uff0c\u5e76\u4f7f\u7528<code>sp.pi<\/code>\u548c<code>sp.E<\/code>\u6765\u5206\u522b\u83b7\u53d6Pi\u548ce\u7684\u503c\u3002Sympy\u5e93\u7684\u4f18\u70b9\u662f\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u663e\u793a\u6570\u503c\uff0c\u8fd8\u53ef\u4ee5\u8fdb\u884c\u7b26\u53f7\u8fd0\u7b97\uff0c\u975e\u5e38\u9002\u5408\u9700\u8981\u8fdb\u884c\u590d\u6742\u6570\u5b66\u8ba1\u7b97\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528numpy\u5e93<\/h3>\n<\/p>\n<p><p>Numpy\u662fPython\u7684\u4e00\u4e2a\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u9ad8\u7ea7\u7684\u6570\u5b66\u51fd\u6570\u548c\u5e38\u91cf\u3002Numpy\u5e93\u4e5f\u5305\u542b\u4e86Pi\u548ce\u7684\u5e38\u91cf\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u5bfc\u5165numpy\u5e93\u5e76\u8bbf\u95ee\u8fd9\u4e9b\u5e38\u91cf\u6765\u663e\u793a\u5b83\u4eec\u7684\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u663e\u793aPi\u7684\u503c<\/strong><\/h2>\n<p>pi_value = np.pi<\/p>\n<p>print(&quot;Pi\u7684\u503c\u662f\uff1a&quot;, pi_value)<\/p>\n<h2><strong>\u663e\u793ae\u7684\u503c<\/strong><\/h2>\n<p>e_value = np.e<\/p>\n<p>print(&quot;e\u7684\u503c\u662f\uff1a&quot;, e_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86numpy\u5e93\uff0c\u5e76\u4f7f\u7528<code>np.pi<\/code>\u548c<code>np.e<\/code>\u6765\u5206\u522b\u83b7\u53d6Pi\u548ce\u7684\u503c\u3002Numpy\u5e93\u5728\u5904\u7406\u6570\u7ec4\u548c\u77e9\u9635\u8fd0\u7b97\u65b9\u9762\u975e\u5e38\u5f3a\u5927\uff0c\u9002\u5408\u9700\u8981\u8fdb\u884c\u5927\u89c4\u6a21\u6570\u503c\u8ba1\u7b97\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Decimal\u6a21\u5757<\/h3>\n<\/p>\n<p><p>Python\u7684decimal\u6a21\u5757\u63d0\u4f9b\u4e86\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u7cbe\u786e\u63a7\u5236\u7684\u529f\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528decimal\u6a21\u5757\u6765\u663e\u793aPi\u548ce\u7684\u503c\uff0c\u5e76\u4e14\u53ef\u4ee5\u6307\u5b9a\u7cbe\u5ea6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from decimal import Decimal, getcontext<\/p>\n<h2><strong>\u8bbe\u7f6e\u7cbe\u5ea6<\/strong><\/h2>\n<p>getcontext().prec = 50<\/p>\n<h2><strong>\u663e\u793aPi\u7684\u503c<\/strong><\/h2>\n<p>pi_value = Decimal(math.pi)<\/p>\n<p>print(&quot;Pi\u7684\u503c\u662f\uff1a&quot;, pi_value)<\/p>\n<h2><strong>\u663e\u793ae\u7684\u503c<\/strong><\/h2>\n<p>e_value = Decimal(math.e)<\/p>\n<p>print(&quot;e\u7684\u503c\u662f\uff1a&quot;, e_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86decimal\u6a21\u5757\uff0c\u5e76\u901a\u8fc7<code>Decimal<\/code>\u7c7b\u5c06Pi\u548ce\u7684\u503c\u8f6c\u6362\u4e3a\u9ad8\u7cbe\u5ea6\u6d6e\u70b9\u6570\u3002<strong>decimal\u6a21\u5757\u7684\u4f18\u70b9\u662f\u53ef\u4ee5\u6307\u5b9a\u7cbe\u5ea6\uff0c\u9002\u5408\u9700\u8981\u9ad8\u7cbe\u5ea6\u8ba1\u7b97\u7684\u573a\u666f\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u624b\u52a8\u8ba1\u7b97Pi\u548ce\u7684\u503c<\/h3>\n<\/p>\n<p><p>\u867d\u7136\u76f4\u63a5\u4f7f\u7528\u5e93\u51fd\u6570\u83b7\u53d6Pi\u548ce\u7684\u503c\u975e\u5e38\u65b9\u4fbf\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u624b\u52a8\u8ba1\u7b97\u5b83\u4eec\u7684\u503c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u8ba1\u7b97\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h4>\u8ba1\u7b97Pi\u7684\u503c<\/h4>\n<\/p>\n<p><p>\u8ba1\u7b97Pi\u7684\u503c\u6709\u8bb8\u591a\u65b9\u6cd5\uff0c\u5176\u4e2d\u4e00\u4e2a\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u83b1\u5e03\u5c3c\u8328\u516c\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u83b1\u5e03\u5c3c\u8328\u516c\u5f0f\u8ba1\u7b97Pi\u7684\u503c<\/p>\n<p>pi_value = 0<\/p>\n<p>for k in range(1000000):<\/p>\n<p>    pi_value += ((-1)  k) \/ (2 * k + 1)<\/p>\n<p>pi_value *= 4<\/p>\n<p>print(&quot;Pi\u7684\u503c\u662f\uff1a&quot;, pi_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u83b1\u5e03\u5c3c\u8328\u516c\u5f0f\u8ba1\u7b97\u4e86Pi\u7684\u503c\u3002\u83b1\u5e03\u5c3c\u8328\u516c\u5f0f\u901a\u8fc7\u9010\u9879\u7d2f\u52a0\u7684\u65b9\u5f0f\u903c\u8fd1Pi\u7684\u503c\uff0c\u8ba1\u7b97\u8fc7\u7a0b\u7b80\u5355\uff0c\u4f46\u6536\u655b\u901f\u5ea6\u8f83\u6162\u3002<\/p>\n<\/p>\n<p><h4>\u8ba1\u7b97e\u7684\u503c<\/h4>\n<\/p>\n<p><p>\u8ba1\u7b97e\u7684\u503c\u4e5f\u6709\u8bb8\u591a\u65b9\u6cd5\uff0c\u5176\u4e2d\u4e00\u4e2a\u5e38\u89c1\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u5176\u6cf0\u52d2\u7ea7\u6570\u5c55\u5f00\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u6cf0\u52d2\u7ea7\u6570\u5c55\u5f00\u8ba1\u7b97e\u7684\u503c<\/p>\n<p>e_value = 0<\/p>\n<p>for n in range(100):<\/p>\n<p>    e_value += 1 \/ math.factorial(n)<\/p>\n<p>print(&quot;e\u7684\u503c\u662f\uff1a&quot;, e_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86e\u7684\u6cf0\u52d2\u7ea7\u6570\u5c55\u5f00\u8ba1\u7b97\u4e86e\u7684\u503c\u3002\u6cf0\u52d2\u7ea7\u6570\u901a\u8fc7\u9010\u9879\u7d2f\u52a0\u7684\u65b9\u5f0f\u903c\u8fd1e\u7684\u503c\uff0c\u8ba1\u7b97\u8fc7\u7a0b\u7b80\u5355\uff0c\u6536\u655b\u901f\u5ea6\u8f83\u5feb\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528mpmath\u5e93<\/h3>\n<\/p>\n<p><p>Mpmath\u662f\u4e00\u4e2a\u7528\u4e8e\u4efb\u610f\u7cbe\u5ea6\u6d6e\u70b9\u8fd0\u7b97\u7684Python\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u7cbe\u786e\u8ba1\u7b97Pi\u548ce\u7684\u503c\u3002\u5b83\u9002\u5408\u9700\u8981\u9ad8\u7cbe\u5ea6\u8ba1\u7b97\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mpmath<\/p>\n<h2><strong>\u8bbe\u7f6e\u7cbe\u5ea6<\/strong><\/h2>\n<p>mpmath.mp.dps = 50<\/p>\n<h2><strong>\u663e\u793aPi\u7684\u503c<\/strong><\/h2>\n<p>pi_value = mpmath.pi<\/p>\n<p>print(&quot;Pi\u7684\u503c\u662f\uff1a&quot;, pi_value)<\/p>\n<h2><strong>\u663e\u793ae\u7684\u503c<\/strong><\/h2>\n<p>e_value = mpmath.e<\/p>\n<p>print(&quot;e\u7684\u503c\u662f\uff1a&quot;, e_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86mpmath\u5e93\uff0c\u5e76\u901a\u8fc7\u8bbe\u7f6e<code>mpmath.mp.dps<\/code>\u6765\u6307\u5b9a\u8ba1\u7b97\u7cbe\u5ea6\u3002\u7136\u540e\uff0c\u6211\u4eec\u4f7f\u7528<code>mpmath.pi<\/code>\u548c<code>mpmath.e<\/code>\u6765\u83b7\u53d6\u9ad8\u7cbe\u5ea6\u7684Pi\u548ce\u7684\u503c\u3002<strong>mpmath\u5e93\u7684\u4f18\u70b9\u662f\u5b83\u53ef\u4ee5\u8fdb\u884c\u4efb\u610f\u7cbe\u5ea6\u7684\u6d6e\u70b9\u8fd0\u7b97\uff0c\u975e\u5e38\u9002\u5408\u9700\u8981\u9ad8\u7cbe\u5ea6\u7684\u79d1\u5b66\u8ba1\u7b97\u3002<\/strong><\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u663e\u793aPi\u548ce\u7684\u503c\u6709\u8bb8\u591a\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528math\u6a21\u5757\u3001sympy\u5e93\u3001numpy\u5e93\u3001decimal\u6a21\u5757\u3001\u624b\u52a8\u8ba1\u7b97\u4ee5\u53campmath\u5e93\u7b49\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u6709\u4e0d\u540c\u7684\u4f18\u7f3a\u70b9\uff0c\u9002\u5408\u4e0d\u540c\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528math\u6a21\u5757<\/strong>\uff1a\u6700\u5e38\u7528\u7684\u65b9\u6cd5\uff0c\u7b80\u5355\u65b9\u4fbf\uff0c\u4e0d\u9700\u8981\u989d\u5916\u5b89\u88c5\u5e93\uff0c\u9002\u5408\u4e00\u822c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528sympy\u5e93<\/strong>\uff1a\u9002\u5408\u9700\u8981\u8fdb\u884c\u7b26\u53f7\u8fd0\u7b97\u548c\u590d\u6742\u6570\u5b66\u8ba1\u7b97\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528numpy\u5e93<\/strong>\uff1a\u9002\u5408\u9700\u8981\u8fdb\u884c\u5927\u89c4\u6a21\u6570\u503c\u8ba1\u7b97\u548c\u77e9\u9635\u8fd0\u7b97\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528decimal\u6a21\u5757<\/strong>\uff1a\u9002\u5408\u9700\u8981\u9ad8\u7cbe\u5ea6\u6d6e\u70b9\u6570\u8ba1\u7b97\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u6307\u5b9a\u7cbe\u5ea6\u3002<\/p>\n<\/p>\n<p><p><strong>\u624b\u52a8\u8ba1\u7b97<\/strong>\uff1a\u9002\u5408\u5b66\u4e60\u548c\u7406\u89e3Pi\u548ce\u7684\u8ba1\u7b97\u539f\u7406\uff0c\u4f46\u8ba1\u7b97\u8fc7\u7a0b\u53ef\u80fd\u8f83\u6162\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528mpmath\u5e93<\/strong>\uff1a\u9002\u5408\u9700\u8981\u4efb\u610f\u7cbe\u5ea6\u6d6e\u70b9\u8fd0\u7b97\u7684\u573a\u666f\uff0c\u975e\u5e38\u9002\u5408\u9ad8\u7cbe\u5ea6\u79d1\u5b66\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><p>\u6839\u636e\u5177\u4f53\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u6211\u4eec\u7684\u4ee3\u7801\u66f4\u52a0\u9ad8\u6548\u548c\u7cbe\u786e\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u5728Python\u4e2d\u663e\u793aPi\u548ce\u7684\u503c\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\u83b7\u53d6\u03c0\uff08pi\uff09\u548ce\u7684\u503c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>math<\/code>\u6a21\u5757\u6765\u83b7\u53d6\u03c0\u548ce\u7684\u503c\u3002\u901a\u8fc7\u5bfc\u5165<code>math<\/code>\u6a21\u5757\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>math.pi<\/code>\u548c<code>math.e<\/code>\u6765\u83b7\u5f97\u8fd9\u4e24\u4e2a\u5e38\u6570\u7684\u7cbe\u786e\u503c\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a  <\/p>\n<pre><code class=\"language-python\">import math\n\nprint(&quot;\u03c0\u7684\u503c\u662f:&quot;, math.pi)\nprint(&quot;e\u7684\u503c\u662f:&quot;, math.e)\n<\/code><\/pre>\n<p><strong>Python\u4e2d\u03c0\u548ce\u7684\u7cbe\u5ea6\u662f\u591a\u5c11\uff1f<\/strong><br \/><code>math<\/code>\u6a21\u5757\u63d0\u4f9b\u7684\u03c0\u548ce\u7684\u503c\u5177\u6709\u76f8\u5f53\u9ad8\u7684\u7cbe\u5ea6\uff0c\u901a\u5e38\u8db3\u4ee5\u6ee1\u8db3\u5927\u591a\u6570\u79d1\u5b66\u548c\u5de5\u7a0b\u8ba1\u7b97\u7684\u9700\u6c42\u3002\u5177\u4f53\u6765\u8bf4\uff0c<code>math.pi<\/code>\u7684\u503c\u5927\u7ea6\u4e3a3.141592653589793\uff0c\u800c<code>math.e<\/code>\u7684\u503c\u7ea6\u4e3a2.718281828459045\u3002\u5bf9\u4e8e\u9700\u8981\u66f4\u9ad8\u7cbe\u5ea6\u7684\u573a\u666f\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528<code>decimal<\/code>\u6a21\u5757\u3002<\/p>\n<p><strong>\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u5176\u4ed6\u5e93\u83b7\u53d6\u03c0\u548ce\u7684\u503c\uff1f<\/strong><br \/>\u9664\u4e86<code>math<\/code>\u6a21\u5757\uff0cPython\u4e2d\u8fd8\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u83b7\u53d6\u03c0\u548ce\u7684\u503c\u3002\u4f8b\u5982\uff0c<code>numpy<\/code>\u5e93\u4e5f\u63d0\u4f9b\u4e86\u8fd9\u4e24\u4e2a\u5e38\u6570\uff0c\u4f7f\u7528\u65b9\u6cd5\u7c7b\u4f3c\uff1a  <\/p>\n<pre><code class=\"language-python\">import numpy as np\n\nprint(&quot;numpy\u4e2d\u7684\u03c0\u503c:&quot;, np.pi)\nprint(&quot;numpy\u4e2d\u7684e\u503c:&quot;, np.e)\n<\/code><\/pre>\n<p>\u6b64\u5916\uff0c<code>sympy<\/code>\u5e93\u53ef\u4ee5\u7528\u4e8e\u7b26\u53f7\u8ba1\u7b97\uff0c\u4e5f\u80fd\u63d0\u4f9b\u8fd9\u4e24\u4e2a\u5e38\u6570\uff0c\u9002\u5408\u9700\u8981\u7b26\u53f7\u8868\u793a\u7684\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u663e\u793aPi\u548ce\u7684\u503c \u5728Python\u4e2d\u663e\u793aPi\u548ce\u7684\u503c\u7684\u65b9\u6cd5\u6709\u5f88\u591a\u79cd\uff0c\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528math\u6a21 [&hellip;]","protected":false},"author":3,"featured_media":1098225,"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\/1098208"}],"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=1098208"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1098208\/revisions"}],"predecessor-version":[{"id":1098226,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1098208\/revisions\/1098226"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1098225"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1098208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1098208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1098208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}