{"id":1011932,"date":"2024-12-27T11:34:23","date_gmt":"2024-12-27T03:34:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1011932.html"},"modified":"2024-12-27T11:34:25","modified_gmt":"2024-12-27T03:34:25","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e4%b9%98%e6%b3%95","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1011932.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u4f7f\u7528\u4e58\u6cd5"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085903\/b7a6c6f5-39f1-49fa-836d-bad806ff37d3.webp\" alt=\"python\u4e2d\u5982\u4f55\u4f7f\u7528\u4e58\u6cd5\" \/><\/p>\n<p><p> \u5728Python\u4e2d\uff0c\u4e58\u6cd5\u64cd\u4f5c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u661f\u53f7\uff08*\uff09\u8fd0\u7b97\u7b26\u6765\u5b9e\u73b0\u3002<strong>Python\u4e2d\u4f7f\u7528\u4e58\u6cd5\u7684\u65b9\u5f0f\u6709\uff1a1. \u57fa\u672c\u7684\u6570\u5b57\u4e58\u6cd5\u30012. \u5217\u8868\u548c\u5b57\u7b26\u4e32\u7684\u91cd\u590d\u30013. \u77e9\u9635\u4e58\u6cd5<\/strong>\u3002\u5176\u4e2d\uff0c\u57fa\u672c\u7684\u6570\u5b57\u4e58\u6cd5\u662f\u6700\u5e38\u7528\u7684\u4e00\u79cd\u3002\u4e0b\u9762\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e09\u79cd\u65b9\u5f0f\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u57fa\u672c\u7684\u6570\u5b57\u4e58\u6cd5<\/p>\n<\/p>\n<p><p>Python\u4e2d\u7684\u57fa\u672c\u6570\u5b57\u4e58\u6cd5\u662f\u6700\u76f4\u89c2\u7684\u5e94\u7528\u3002\u65e0\u8bba\u662f\u6574\u6570\u8fd8\u662f\u6d6e\u70b9\u6570\uff0c\u4e58\u6cd5\u8fd0\u7b97\u7b26\uff08*\uff09\u90fd\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u4e24\u4e2a\u6570\u5b57\u7684\u4e58\u6cd5\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6574\u6570\u548c\u6d6e\u70b9\u6570\u7684\u4e58\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u65e0\u8bba\u662f\u6574\u578b\u6570\u636e\u8fd8\u662f\u6d6e\u70b9\u578b\u6570\u636e\uff0c\u4f7f\u7528*\u8fd0\u7b97\u7b26\u90fd\u53ef\u4ee5\u5b9e\u73b0\u4e58\u6cd5\u8fd0\u7b97\u3002\u6574\u6570\u4e58\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u7ed3\u679c\uff0c\u800c\u6d6e\u70b9\u6570\u4e58\u6cd5\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6d6e\u70b9\u6570\u7ed3\u679c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6574\u6570\u4e58\u6cd5<\/p>\n<p>result_int = 5 * 3<\/p>\n<p>print(result_int)  # \u8f93\u51fa\uff1a15<\/p>\n<h2><strong>\u6d6e\u70b9\u6570\u4e58\u6cd5<\/strong><\/h2>\n<p>result_float = 5.0 * 3.0<\/p>\n<p>print(result_float)  # \u8f93\u51fa\uff1a15.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6df7\u5408\u7c7b\u578b\u4e58\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53\u6574\u6570\u548c\u6d6e\u70b9\u6570\u76f8\u4e58\u65f6\uff0c\u7ed3\u679c\u4f1a\u662f\u6d6e\u70b9\u6570\u3002\u8fd9\u662f\u56e0\u4e3aPython\u4f1a\u81ea\u52a8\u5c06\u6574\u6570\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u4ee5\u786e\u4fdd\u7ed3\u679c\u7684\u7cbe\u5ea6\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result_mixed = 5 * 3.0<\/p>\n<p>print(result_mixed)  # \u8f93\u51fa\uff1a15.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e8c\u3001\u5217\u8868\u548c\u5b57\u7b26\u4e32\u7684\u91cd\u590d<\/p>\n<\/p>\n<p><p>\u4e58\u6cd5\u8fd0\u7b97\u7b26\u5728Python\u4e2d\u4e0d\u4ec5\u7528\u4e8e\u6570\u5b57\u8fd0\u7b97\uff0c\u8fd8\u53ef\u4ee5\u7528\u4e8e\u91cd\u590d\u5217\u8868\u548c\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5b57\u7b26\u4e32\u7684\u91cd\u590d<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53*\u8fd0\u7b97\u7b26\u4e0e\u5b57\u7b26\u4e32\u7ed3\u5408\u65f6\uff0c\u5b83\u4f1a\u8fd4\u56de\u4e00\u4e2a\u91cd\u590d\u8be5\u5b57\u7b26\u4e32\u6307\u5b9a\u6b21\u6570\u7684\u65b0\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">text = &quot;Hello&quot;<\/p>\n<p>repeated_text = text * 3<\/p>\n<p>print(repeated_text)  # \u8f93\u51fa\uff1aHelloHelloHello<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5217\u8868\u7684\u91cd\u590d<\/strong><\/li>\n<\/ol>\n<p><p>\u7c7b\u4f3c\u4e8e\u5b57\u7b26\u4e32\uff0c\u4e58\u6cd5\u8fd0\u7b97\u7b26\u53ef\u4ee5\u7528\u4e8e\u5217\u8868\uff0c\u4ee5\u521b\u5efa\u4e00\u4e2a\u91cd\u590d\u8be5\u5217\u8868\u6307\u5b9a\u6b21\u6570\u7684\u65b0\u5217\u8868\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3]<\/p>\n<p>repeated_numbers = numbers * 2<\/p>\n<p>print(repeated_numbers)  # \u8f93\u51fa\uff1a[1, 2, 3, 1, 2, 3]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u77e9\u9635\u4e58\u6cd5<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u77e9\u9635\u4e58\u6cd5\uff0cPython\u4e2d\u5e38\u7528\u7684\u5e93\u662fNumPy\u3002NumPy\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u529f\u80fd\u6765\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u548c\u77e9\u9635\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528NumPy\u8fdb\u884c\u77e9\u9635\u4e58\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5NumPy\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528NumPy\u4e2d\u7684<code>dot<\/code>\u51fd\u6570\u6216<code>@<\/code>\u8fd0\u7b97\u7b26\u8fdb\u884c\u77e9\u9635\u4e58\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u5b9a\u4e49\u4e24\u4e2a\u77e9\u9635<\/strong><\/h2>\n<p>matrix_a = np.array([[1, 2], [3, 4]])<\/p>\n<p>matrix_b = np.array([[5, 6], [7, 8]])<\/p>\n<h2><strong>\u4f7f\u7528dot\u51fd\u6570<\/strong><\/h2>\n<p>result_matrix_dot = np.dot(matrix_a, matrix_b)<\/p>\n<p>print(result_matrix_dot)<\/p>\n<h2><strong>\u8f93\u51fa\uff1a<\/strong><\/h2>\n<h2><strong>[[19 22]<\/strong><\/h2>\n<h2><strong> [43 50]]<\/strong><\/h2>\n<h2><strong>\u4f7f\u7528@\u8fd0\u7b97\u7b26<\/strong><\/h2>\n<p>result_matrix_at = matrix_a @ matrix_b<\/p>\n<p>print(result_matrix_at)<\/p>\n<h2><strong>\u8f93\u51fa\uff1a<\/strong><\/h2>\n<h2><strong>[[19 22]<\/strong><\/h2>\n<h2><strong> [43 50]]<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>NumPy\u7684\u5e7f\u64ad\u673a\u5236<\/strong><\/li>\n<\/ol>\n<p><p>NumPy\u7684\u5e7f\u64ad\u673a\u5236\u5141\u8bb8\u5bf9\u4e0d\u540c\u5f62\u72b6\u7684\u6570\u7ec4\u8fdb\u884c\u8fd0\u7b97\u3002\u4e58\u6cd5\u8fd0\u7b97\u65f6\uff0c\u5982\u679c\u5f62\u72b6\u4e0d\u540c\uff0cNumPy\u4f1a\u81ea\u52a8\u201c\u6269\u5c55\u201d\u8f83\u5c0f\u7684\u6570\u7ec4\uff0c\u4ee5\u4fbf\u6267\u884c\u8fd0\u7b97\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">array_1 = np.array([1, 2, 3])<\/p>\n<p>array_2 = np.array([[1], [2], [3]])<\/p>\n<h2><strong>\u5e7f\u64ad\u673a\u5236\u4f7f\u5f97array_1\u4e58\u4ee5array_2<\/strong><\/h2>\n<p>result_broadcast = array_1 * array_2<\/p>\n<p>print(result_broadcast)<\/p>\n<h2><strong>\u8f93\u51fa\uff1a<\/strong><\/h2>\n<h2><strong>[[1 2 3]<\/strong><\/h2>\n<h2><strong> [2 4 6]<\/strong><\/h2>\n<h2><strong> [3 6 9]]<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u5176\u4ed6\u4f7f\u7528\u4e58\u6cd5\u7684\u573a\u666f<\/p>\n<\/p>\n<ol>\n<li><strong>\u7ed3\u5408\u5176\u4ed6\u8fd0\u7b97\u7b26<\/strong><\/li>\n<\/ol>\n<p><p>\u4e58\u6cd5\u8fd0\u7b97\u53ef\u4ee5\u4e0e\u5176\u4ed6\u8fd0\u7b97\u7b26\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u8ba1\u7b97\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8ba1\u7b97\u8868\u8fbe\u5f0f (2 + 3) * (4 - 1)<\/p>\n<p>result_combined = (2 + 3) * (4 - 1)<\/p>\n<p>print(result_combined)  # \u8f93\u51fa\uff1a15<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u4e58\u6cd5\u7b80\u5316\u4ee3\u7801<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e58\u6cd5\u8fd0\u7b97\u53ef\u4ee5\u5e2e\u52a9\u7b80\u5316\u4ee3\u7801\u3002\u4f8b\u5982\uff0c\u6c42\u4e00\u7cfb\u5217\u6570\u7684\u4e58\u79ef\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u548c\u4e58\u6cd5\u8fd0\u7b97\u7b26\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3, 4, 5]<\/p>\n<p>product = 1<\/p>\n<p>for number in numbers:<\/p>\n<p>    product *= number<\/p>\n<p>print(product)  # \u8f93\u51fa\uff1a120<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u81ea\u5b9a\u4e49\u4e58\u6cd5\u8fd0\u7b97<\/strong><\/li>\n<\/ol>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u91cd\u8f7d\u7279\u6b8a\u65b9\u6cd5<code>__mul__<\/code>\u6765\u81ea\u5b9a\u4e49\u5bf9\u8c61\u7684\u4e58\u6cd5\u884c\u4e3a\u3002\u8fd9\u5bf9\u4e8e\u9700\u8981\u81ea\u5b9a\u4e49\u4e58\u6cd5\u903b\u8f91\u7684\u7c7b\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Vector:<\/p>\n<p>    def __init__(self, x, y):<\/p>\n<p>        self.x = x<\/p>\n<p>        self.y = y<\/p>\n<p>    def __mul__(self, other):<\/p>\n<p>        if isinstance(other, (int, float)):<\/p>\n<p>            return Vector(self.x * other, self.y * other)<\/p>\n<p>        r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se ValueError(&quot;\u53ea\u80fd\u5c06\u5411\u91cf\u4e0e\u6807\u91cf\u76f8\u4e58&quot;)<\/p>\n<p>    def __repr__(self):<\/p>\n<p>        return f&quot;Vector({self.x}, {self.y})&quot;<\/p>\n<p>vector = Vector(2, 3)<\/p>\n<p>scaled_vector = vector * 3<\/p>\n<p>print(scaled_vector)  # \u8f93\u51fa\uff1aVector(6, 9)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u4e58\u6cd5\u5728\u6570\u636e\u79d1\u5b66\u4e2d\u7684\u5e94\u7528<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u79d1\u5b66\u9886\u57df\uff0c\u4e58\u6cd5\u8fd0\u7b97\u662f\u8bb8\u591a\u7b97\u6cd5\u7684\u6838\u5fc3\u90e8\u5206\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u77e9\u9635\u548c\u5411\u91cf\u65f6\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u7ebf\u6027\u4ee3\u6570\u4e2d\u7684\u4e58\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u8bb8\u591a<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7b97\u6cd5\u4e2d\uff0c\u7ebf\u6027\u4ee3\u6570\u662f\u57fa\u7840\u3002\u4e58\u6cd5\u8fd0\u7b97\u5728\u77e9\u9635\u548c\u5411\u91cf\u7684\u8868\u793a\u548c\u8ba1\u7b97\u4e2d\u53d1\u6325\u7740\u5173\u952e\u4f5c\u7528\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6570\u636e\u5904\u7406\u4e2d\u7684\u4e58\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u4e58\u6cd5\u8fd0\u7b97\u5728\u6570\u636e\u5904\u7406\u548c\u7279\u5f81\u5de5\u7a0b\u4e2d\u4e5f\u5f88\u5e38\u89c1\u3002\u4f8b\u5982\uff0c\u6807\u51c6\u5316\u6570\u636e\u65f6\uff0c\u9700\u8981\u5bf9\u6bcf\u4e2a\u7279\u5f81\u8fdb\u884c\u4e58\u6cd5\u8fd0\u7b97\uff0c\u4ee5\u8c03\u6574\u5176\u5c3a\u5ea6\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u7edf\u8ba1\u5b66\u4e2d\u7684\u4e58\u6cd5<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u7edf\u8ba1\u5b66\u4e2d\uff0c\u4e58\u6cd5\u8fd0\u7b97\u7528\u4e8e\u8ba1\u7b97\u6982\u7387\u3001\u671f\u671b\u503c\u548c\u65b9\u5dee\u7b49\u57fa\u672c\u7edf\u8ba1\u91cf\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001Python\u4e58\u6cd5\u7684\u6027\u80fd\u4f18\u5316<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528NumPy\u8fdb\u884c\u6279\u91cf\u8fd0\u7b97<\/strong><\/li>\n<\/ol>\n<p><p>NumPy\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u6027\u80fd\u4f18\u5f02\u3002\u901a\u8fc7\u5229\u7528NumPy\u7684\u6279\u91cf\u8fd0\u7b97\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u8ba1\u7b97<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u4e58\u6cd5\u8fd0\u7b97\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u5728\u5faa\u73af\u4e2d\u91cd\u590d\u8ba1\u7b97\u76f8\u540c\u7684\u4e58\u79ef\uff0c\u5e94\u8be5\u5c06\u5176\u79fb\u51fa\u5faa\u73af\u4ee5\u51cf\u5c11\u8ba1\u7b97\u6b21\u6570\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4f7f\u7528Python\u5185\u7f6e\u51fd\u6570<\/strong><\/li>\n<\/ol>\n<p><p>Python\u5185\u7f6e\u51fd\u6570\u901a\u5e38\u7ecf\u8fc7\u4f18\u5316\uff0c\u6027\u80fd\u66f4\u597d\u3002\u5728\u8fdb\u884c\u590d\u6742\u8ba1\u7b97\u65f6\uff0c\u5c3d\u91cf\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4e58\u6cd5\u8fd0\u7b97\u662f\u4e00\u4e2a\u57fa\u672c\u4e14\u5f3a\u5927\u7684\u529f\u80fd\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u6570\u5b57\u4e58\u6cd5\uff0c\u8fd8\u662f\u590d\u6742\u7684\u77e9\u9635\u8fd0\u7b97\uff0cPython\u90fd\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u5de5\u5177\u548c\u5e93\u6765\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u901a\u8fc7\u5408\u7406\u5730\u4f7f\u7528\u4e58\u6cd5\u8fd0\u7b97\uff0c\u53ef\u4ee5\u5728\u8bb8\u591a\u9886\u57df\u4e2d\u5b9e\u73b0\u9ad8\u6548\u7684\u6570\u636e\u5904\u7406\u548c\u8ba1\u7b97\u3002\u901a\u8fc7\u6df1\u5165\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u6280\u5de7\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u7f16\u5199\u51fa\u66f4\u52a0\u9ad8\u6548\u548c\u53ef\u8bfb\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\u5982\u4f55\u8fdb\u884c\u4e58\u6cd5\u8fd0\u7b97\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u4e58\u6cd5\u8fd0\u7b97\u4f7f\u7528\u661f\u53f7\uff08*\uff09\u6765\u8868\u793a\u3002\u4f8b\u5982\uff0c\u5982\u679c\u8981\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b575\u548c3\u7684\u4e58\u79ef\uff0c\u53ef\u4ee5\u4f7f\u7528\u8868\u8fbe\u5f0f<code>5 * 3<\/code>\uff0c\u5176\u7ed3\u679c\u4e3a15\u3002\u53ef\u4ee5\u76f4\u63a5\u5728Python\u7684\u4ea4\u4e92\u5f0f\u73af\u5883\u4e2d\u6216\u5728\u811a\u672c\u4e2d\u4f7f\u7528\u8fd9\u4e2a\u8bed\u6cd5\u8fdb\u884c\u4e58\u6cd5\u8fd0\u7b97\u3002<\/p>\n<p><strong>\u80fd\u5426\u5728Python\u4e2d\u5bf9\u5217\u8868\u6216\u6570\u7ec4\u8fdb\u884c\u4e58\u6cd5\u8fd0\u7b97\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u652f\u6301\u5bf9\u5217\u8868\u548cNumPy\u6570\u7ec4\u8fdb\u884c\u4e58\u6cd5\u8fd0\u7b97\u3002\u5bf9\u4e8e\u5217\u8868\uff0c\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u6765\u5b9e\u73b0\u5143\u7d20\u4e4b\u95f4\u7684\u4e58\u6cd5\u3002\u4f8b\u5982\uff0c<code>[x * 2 for x in [1, 2, 3]]<\/code>\u4f1a\u8fd4\u56de<code>[2, 4, 6]<\/code>\u3002\u800c\u5bf9\u4e8eNumPy\u6570\u7ec4\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>*<\/code>\u8fd0\u7b97\u7b26\uff0c<code>numpy.array([1, 2, 3]) * 2<\/code>\u7684\u7ed3\u679c\u4f1a\u662f<code>array([2, 4, 6])<\/code>\u3002<\/p>\n<p><strong>Python\u4e2d\u7684\u4e58\u6cd5\u8fd0\u7b97\u662f\u5426\u652f\u6301\u6d6e\u70b9\u6570\uff1f<\/strong><br \/>\u4e58\u6cd5\u8fd0\u7b97\u5728Python\u4e2d\u4e0d\u4ec5\u652f\u6301\u6574\u6570\uff0c\u8fd8\u53ef\u4ee5\u5904\u7406\u6d6e\u70b9\u6570\u3002\u6bd4\u5982\uff0c\u8ba1\u7b97<code>2.5 * 4.0<\/code>\u4f1a\u5f97\u523010.0\u3002\u65e0\u8bba\u662f\u6574\u6570\u8fd8\u662f\u6d6e\u70b9\u6570\uff0cPython\u4f1a\u81ea\u52a8\u5904\u7406\u6570\u636e\u7c7b\u578b\u5e76\u8fd4\u56de\u76f8\u5e94\u7684\u7ed3\u679c\u3002\u5728\u8fdb\u884c\u6570\u5b66\u8fd0\u7b97\u65f6\uff0c\u786e\u4fdd\u4f7f\u7528\u5408\u9002\u7684\u7c7b\u578b\uff0c\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u7c7b\u578b\u9519\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u4e58\u6cd5\u64cd\u4f5c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u661f\u53f7\uff08*\uff09\u8fd0\u7b97\u7b26\u6765\u5b9e\u73b0\u3002Python\u4e2d\u4f7f\u7528\u4e58\u6cd5\u7684\u65b9\u5f0f\u6709\uff1a1. \u57fa\u672c\u7684\u6570\u5b57 [&hellip;]","protected":false},"author":3,"featured_media":1011942,"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\/1011932"}],"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=1011932"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1011932\/revisions"}],"predecessor-version":[{"id":1011944,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1011932\/revisions\/1011944"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1011942"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1011932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1011932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1011932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}