{"id":1076293,"date":"2025-01-08T11:52:03","date_gmt":"2025-01-08T03:52:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1076293.html"},"modified":"2025-01-08T11:52:05","modified_gmt":"2025-01-08T03:52:05","slug":"python%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bf%9b%e8%a1%8c%e5%87%bd%e6%95%b0%e7%9a%84%e5%ae%9a%e4%b9%89-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1076293.html","title":{"rendered":"python\u4e2d\u5982\u4f55\u8fdb\u884c\u51fd\u6570\u7684\u5b9a\u4e49"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24180933\/b400f0ca-6827-453e-92c5-21894bc8df8c.webp\" alt=\"python\u4e2d\u5982\u4f55\u8fdb\u884c\u51fd\u6570\u7684\u5b9a\u4e49\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u5b9a\u4e49\u51fd\u6570\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\u4f7f\u7528def\u5173\u952e\u5b57\u3001\u547d\u540d\u51fd\u6570\u3001\u6dfb\u52a0\u53c2\u6570\u3001\u7f16\u5199\u51fd\u6570\u4f53\u53ca\u8fd4\u56de\u503c\u3002<\/strong> \u51fd\u6570\u662f\u7ec4\u7ec7\u4ee3\u7801\u7684\u4e00\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u91cd\u7528\u6027\u3002\u4e0b\u9762\u6211\u4eec\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u5728Python\u4e2d\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u51fd\u6570\u7684\u57fa\u672c\u5b9a\u4e49<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u51fd\u6570\u7684\u5b9a\u4e49\u4e3b\u8981\u662f\u901a\u8fc7<code>def<\/code>\u5173\u952e\u5b57\u6765\u5b9e\u73b0\u7684\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u51fd\u6570\u5b9a\u4e49\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def my_function():<\/p>\n<p>    print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u51fd\u6570\u6ca1\u6709\u53c2\u6570\uff0c\u6267\u884c\u65f6\u4f1a\u6253\u5370&quot;Hello, World!&quot;\u3002\u51fd\u6570\u5b9a\u4e49\u7684\u57fa\u672c\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def function_name(parameters):<\/p>\n<p>    &quot;&quot;&quot;docstring&quot;&quot;&quot;<\/p>\n<p>    function_body<\/p>\n<p>    return expression<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>def<\/code>\uff1a\u51fd\u6570\u5b9a\u4e49\u7684\u5173\u952e\u5b57<\/li>\n<li><code>function_name<\/code>\uff1a\u51fd\u6570\u7684\u540d\u79f0<\/li>\n<li><code>parameters<\/code>\uff1a\u53c2\u6570\uff0c\u591a\u4e2a\u53c2\u6570\u7528\u9017\u53f7\u5206\u9694<\/li>\n<li><code>&quot;&quot;&quot;docstring&quot;&quot;&quot;<\/code>\uff1a\u51fd\u6570\u7684\u6587\u6863\u5b57\u7b26\u4e32\uff08\u53ef\u9009\uff09<\/li>\n<li><code>function_body<\/code>\uff1a\u51fd\u6570\u7684\u4e3b\u4f53<\/li>\n<li><code>return expression<\/code>\uff1a\u8fd4\u56de\u503c\uff08\u53ef\u9009\uff09<\/li>\n<\/ul>\n<p><h3>\u4e8c\u3001\u51fd\u6570\u53c2\u6570<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u53c2\u6570\u662f\u51fd\u6570\u5b9a\u4e49\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u90e8\u5206\u3002\u51fd\u6570\u53c2\u6570\u53ef\u4ee5\u5206\u4e3a\u4f4d\u7f6e\u53c2\u6570\u3001\u9ed8\u8ba4\u53c2\u6570\u3001\u5173\u952e\u5b57\u53c2\u6570\u548c\u53ef\u53d8\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f4d\u7f6e\u53c2\u6570<\/h4>\n<\/p>\n<p><p>\u4f4d\u7f6e\u53c2\u6570\u662f\u6700\u5e38\u89c1\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u8c03\u7528\u51fd\u6570\u65f6\u9700\u8981\u6309\u7167\u5b9a\u4e49\u65f6\u7684\u987a\u5e8f\u4f20\u9012\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    print(f&quot;Hello, {name}!&quot;)<\/p>\n<p>greet(&quot;Alice&quot;)  # \u8f93\u51fa: Hello, Alice!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u9ed8\u8ba4\u53c2\u6570<\/h4>\n<\/p>\n<p><p>\u9ed8\u8ba4\u53c2\u6570\u5141\u8bb8\u5728\u51fd\u6570\u5b9a\u4e49\u65f6\u4e3a\u53c2\u6570\u63d0\u4f9b\u9ed8\u8ba4\u503c\u3002\u5982\u679c\u8c03\u7528\u51fd\u6570\u65f6\u6ca1\u6709\u4f20\u9012\u8be5\u53c2\u6570\uff0c\u5219\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name=&quot;World&quot;):<\/p>\n<p>    print(f&quot;Hello, {name}!&quot;)<\/p>\n<p>greet()         # \u8f93\u51fa: Hello, World!<\/p>\n<p>greet(&quot;Alice&quot;)  # \u8f93\u51fa: Hello, Alice!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5173\u952e\u5b57\u53c2\u6570<\/h4>\n<\/p>\n<p><p>\u5173\u952e\u5b57\u53c2\u6570\u5141\u8bb8\u5728\u8c03\u7528\u51fd\u6570\u65f6\u901a\u8fc7\u53c2\u6570\u540d\u6307\u5b9a\u53c2\u6570\u503c\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u53c2\u6570\u987a\u5e8f\u7684\u9650\u5236\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(greeting, name):<\/p>\n<p>    print(f&quot;{greeting}, {name}!&quot;)<\/p>\n<p>greet(name=&quot;Alice&quot;, greeting=&quot;Hi&quot;)  # \u8f93\u51fa: Hi, Alice!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u53ef\u53d8\u53c2\u6570<\/h4>\n<\/p>\n<p><p>\u53ef\u53d8\u53c2\u6570\u5141\u8bb8\u51fd\u6570\u63a5\u53d7\u4efb\u610f\u6570\u91cf\u7684\u4f4d\u7f6e\u53c2\u6570\u6216\u5173\u952e\u5b57\u53c2\u6570\uff0c\u5206\u522b\u4f7f\u7528<code>*args<\/code>\u548c<code>kwargs<\/code>\u6765\u5b9a\u4e49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(*names):<\/p>\n<p>    for name in names:<\/p>\n<p>        print(f&quot;Hello, {name}!&quot;)<\/p>\n<p>greet(&quot;Alice&quot;, &quot;Bob&quot;, &quot;Charlie&quot;)<\/p>\n<h2><strong>\u8f93\u51fa:<\/strong><\/h2>\n<h2><strong>Hello, Alice!<\/strong><\/h2>\n<h2><strong>Hello, Bob!<\/strong><\/h2>\n<h2><strong>Hello, Charlie!<\/strong><\/h2>\n<p>def greet(kwargs):<\/p>\n<p>    for key, value in kwargs.items():<\/p>\n<p>        print(f&quot;{key}: {value}&quot;)<\/p>\n<p>greet(name=&quot;Alice&quot;, age=30)<\/p>\n<h2><strong>\u8f93\u51fa:<\/strong><\/h2>\n<h2><strong>name: Alice<\/strong><\/h2>\n<h2><strong>age: 30<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u51fd\u6570\u8fd4\u56de\u503c<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u53ef\u4ee5\u6709\u8fd4\u56de\u503c\uff0c\u901a\u8fc7<code>return<\/code>\u5173\u952e\u5b57\u5b9e\u73b0\u3002\u5982\u679c\u6ca1\u6709<code>return<\/code>\u8bed\u53e5\uff0c\u51fd\u6570\u9ed8\u8ba4\u8fd4\u56de<code>None<\/code>\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>result = add(3, 5)<\/p>\n<p>print(result)  # \u8f93\u51fa: 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u9012\u5f52\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u9012\u5f52\u51fd\u6570\u662f\u6307\u5728\u51fd\u6570\u5185\u90e8\u8c03\u7528\u81ea\u8eab\u7684\u51fd\u6570\u3002\u9012\u5f52\u51fd\u6570\u9700\u8981\u5b9a\u4e49\u57fa\u51c6\u60c5\u51b5\u548c\u9012\u5f52\u60c5\u51b5\uff0c\u4ee5\u907f\u514d\u65e0\u9650\u5faa\u73af\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def factorial(n):<\/p>\n<p>    if n == 1:<\/p>\n<p>        return 1<\/p>\n<p>    else:<\/p>\n<p>        return n * factorial(n - 1)<\/p>\n<p>print(factorial(5))  # \u8f93\u51fa: 120<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u533f\u540d\u51fd\u6570\uff08Lambda\u51fd\u6570\uff09<\/h3>\n<\/p>\n<p><p>\u533f\u540d\u51fd\u6570\u4f7f\u7528<code>lambda<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\uff0c\u901a\u5e38\u7528\u4e8e\u7b80\u5355\u7684\u51fd\u6570\u5b9a\u4e49\u3002\u533f\u540d\u51fd\u6570\u53ef\u4ee5\u6ca1\u6709\u540d\u5b57\uff0c\u5e76\u4e14\u53ea\u80fd\u5305\u542b\u4e00\u4e2a\u8868\u8fbe\u5f0f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">add = lambda x, y: x + y<\/p>\n<p>print(add(3, 5))  # \u8f93\u51fa: 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u51fd\u6570\u6587\u6863\u5b57\u7b26\u4e32\uff08Docstring\uff09<\/h3>\n<\/p>\n<p><p>\u6587\u6863\u5b57\u7b26\u4e32\u662f\u7528\u4e8e\u63cf\u8ff0\u51fd\u6570\u7528\u9014\u7684\u5b57\u7b26\u4e32\uff0c\u653e\u5728\u51fd\u6570\u5b9a\u4e49\u7684\u7b2c\u4e00\u884c\u3002\u6587\u6863\u5b57\u7b26\u4e32\u53ef\u4ee5\u901a\u8fc7\u51fd\u6570\u7684<code>__doc__<\/code>\u5c5e\u6027\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    &quot;&quot;&quot;This function greets the person passed in as a parameter.&quot;&quot;&quot;<\/p>\n<p>    print(f&quot;Hello, {name}!&quot;)<\/p>\n<p>print(greet.__doc__)  # \u8f93\u51fa: This function greets the person passed in as a parameter.<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u9ad8\u9636\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u9ad8\u9636\u51fd\u6570\u662f\u6307\u53ef\u4ee5\u63a5\u53d7\u5176\u4ed6\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u6216\u8fd4\u56de\u503c\u7684\u51fd\u6570\u3002\u8fd9\u7c7b\u51fd\u6570\u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\u975e\u5e38\u5e38\u89c1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(x, y):<\/p>\n<p>    return x + y<\/p>\n<p>def operate(func, a, b):<\/p>\n<p>    return func(a, b)<\/p>\n<p>result = operate(add, 3, 5)<\/p>\n<p>print(result)  # \u8f93\u51fa: 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u88c5\u9970\u5668<\/h3>\n<\/p>\n<p><p>\u88c5\u9970\u5668\u662f\u7528\u4e8e\u4fee\u6539\u51fd\u6570\u884c\u4e3a\u7684\u9ad8\u7ea7\u5de5\u5177\u3002\u88c5\u9970\u5668\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u8fd4\u56de\u51fd\u6570\u7684\u51fd\u6570\uff0c\u901a\u5e38\u4f7f\u7528<code>@<\/code>\u8bed\u6cd5\u7cd6\u5e94\u7528\u4e8e\u51fd\u6570\u5b9a\u4e49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def my_decorator(func):<\/p>\n<p>    def wrapper():<\/p>\n<p>        print(&quot;Something is happening before the function is called.&quot;)<\/p>\n<p>        func()<\/p>\n<p>        print(&quot;Something is happening after the function is called.&quot;)<\/p>\n<p>    return wrapper<\/p>\n<p>@my_decorator<\/p>\n<p>def say_hello():<\/p>\n<p>    print(&quot;Hello!&quot;)<\/p>\n<p>say_hello()<\/p>\n<h2><strong>\u8f93\u51fa:<\/strong><\/h2>\n<h2><strong>Something is happening before the function is called.<\/strong><\/h2>\n<h2><strong>Hello!<\/strong><\/h2>\n<h2><strong>Something is happening after the function is called.<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e5d\u3001\u5185\u7f6e\u51fd\u6570\u548c\u81ea\u5b9a\u4e49\u51fd\u6570<\/h3>\n<\/p>\n<p><p>Python \u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u51fd\u6570\uff0c\u5982<code>len()<\/code>, <code>max()<\/code>, <code>min()<\/code>, <code>sum()<\/code>\u7b49\u3002\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5b9a\u4e49\u81ea\u5df1\u7684\u51fd\u6570\u6765\u6ee1\u8db3\u7279\u5b9a\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def custom_max(a, b):<\/p>\n<p>    return a if a &gt; b else b<\/p>\n<p>print(custom_max(10, 20))  # \u8f93\u51fa: 20<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u51fd\u6570\u7684\u4f5c\u7528\u57df<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u7684\u4f5c\u7528\u57df\u51b3\u5b9a\u4e86\u53d8\u91cf\u7684\u53ef\u8bbf\u95ee\u6027\u3002Python \u4e2d\u6709\u5c40\u90e8\u4f5c\u7528\u57df\u548c\u5168\u5c40\u4f5c\u7528\u57df\u3002\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u548c\u4f7f\u7528\uff0c\u5168\u5c40\u53d8\u91cf\u5728\u51fd\u6570\u5916\u90e8\u5b9a\u4e49\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\u548c\u4fee\u6539\uff08\u9700\u8981\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57\uff09\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 10  # \u5168\u5c40\u53d8\u91cf<\/p>\n<p>def modify_global():<\/p>\n<p>    global x<\/p>\n<p>    x = 20  # \u4fee\u6539\u5168\u5c40\u53d8\u91cf<\/p>\n<p>modify_global()<\/p>\n<p>print(x)  # \u8f93\u51fa: 20<\/p>\n<p>def local_scope():<\/p>\n<p>    y = 30  # \u5c40\u90e8\u53d8\u91cf<\/p>\n<p>    print(y)<\/p>\n<p>local_scope()  # \u8f93\u51fa: 30<\/p>\n<h2><strong>print(y)  # \u62a5\u9519\uff1aNameError: name &#39;y&#39; is not defined<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u4e86\u89e3\u4e86\u5982\u4f55\u5728Python\u4e2d\u5b9a\u4e49\u51fd\u6570\u53ca\u5176\u76f8\u5173\u7684\u6982\u5ff5\u548c\u4f7f\u7528\u65b9\u6cd5\u3002\u638c\u63e1\u8fd9\u4e9b\u77e5\u8bc6\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u53ef\u8bfb\u6027\u66f4\u5f3a\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5728Python\u4e2d\u5b9a\u4e49\u51fd\u6570\u7684\u57fa\u672c\u8bed\u6cd5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u51fd\u6570\u7684\u5b9a\u4e49\u901a\u5e38\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\uff0c\u540e\u9762\u7d27\u8ddf\u51fd\u6570\u540d\u548c\u5706\u62ec\u53f7\u3002\u51fd\u6570\u4f53\u9700\u8981\u7f29\u8fdb\u4ee5\u6807\u8bc6\u5176\u8303\u56f4\u3002\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">def function_name(parameters):\n    # \u51fd\u6570\u4f53\n    return value\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684\u52a0\u6cd5\u51fd\u6570\uff1a  <\/p>\n<pre><code class=\"language-python\">def add(a, b):\n    return a + b\n<\/code><\/pre>\n<p><strong>\u6211\u53ef\u4ee5\u5728Python\u51fd\u6570\u4e2d\u4f7f\u7528\u9ed8\u8ba4\u53c2\u6570\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u652f\u6301\u9ed8\u8ba4\u53c2\u6570\uff0c\u4f7f\u5f97\u5728\u8c03\u7528\u51fd\u6570\u65f6\u53ef\u4ee5\u7701\u7565\u67d0\u4e9b\u53c2\u6570\u3002\u5b9a\u4e49\u65f6\u4e3a\u53c2\u6570\u6307\u5b9a\u4e00\u4e2a\u9ed8\u8ba4\u503c\u5373\u53ef\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">def greet(name=&quot;Guest&quot;):\n    return f&quot;Hello, {name}!&quot;\n<\/code><\/pre>\n<p>\u8c03\u7528<code>greet()<\/code>\u5c06\u8fd4\u56de\u201cHello, Guest!\u201d\u800c\u8c03\u7528<code>greet(&quot;Alice&quot;)<\/code>\u5c06\u8fd4\u56de\u201cHello, Alice!\u201d\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u51fd\u6570\u4e2d\u5904\u7406\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\u6765\u5904\u7406\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\uff1a\u4f7f\u7528\u661f\u53f7\uff08*\uff09\u548c\u53cc\u661f\u53f7\uff08**\uff09\u3002\u5355\u4e2a\u661f\u53f7\u7528\u4e8e\u63a5\u6536\u4e0d\u5b9a\u6570\u91cf\u7684\u4f4d\u7f6e\u53c2\u6570\uff0c\u800c\u53cc\u661f\u53f7\u7528\u4e8e\u63a5\u6536\u4e0d\u5b9a\u6570\u91cf\u7684\u5173\u952e\u5b57\u53c2\u6570\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">def print_numbers(*args):\n    for number in args:\n        print(number)\n\ndef print_info(**kwargs):\n    for key, value in kwargs.items():\n        print(f&quot;{key}: {value}&quot;)\n<\/code><\/pre>\n<p>\u8c03\u7528<code>print_numbers(1, 2, 3)<\/code>\u5c06\u8f93\u51fa1, 2, 3\uff0c\u800c\u8c03\u7528<code>print_info(name=&quot;Alice&quot;, age=30)<\/code>\u5c06\u8f93\u51fa<code>name: Alice<\/code>\u548c<code>age: 30<\/code>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u5b9a\u4e49\u51fd\u6570\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\u4f7f\u7528def\u5173\u952e\u5b57\u3001\u547d\u540d\u51fd\u6570\u3001\u6dfb\u52a0\u53c2\u6570\u3001\u7f16\u5199\u51fd\u6570\u4f53\u53ca\u8fd4\u56de\u503c\u3002 \u51fd\u6570\u662f\u7ec4\u7ec7 [&hellip;]","protected":false},"author":3,"featured_media":1076302,"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\/1076293"}],"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=1076293"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076293\/revisions"}],"predecessor-version":[{"id":1076304,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1076293\/revisions\/1076304"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1076302"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1076293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1076293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1076293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}