{"id":1159947,"date":"2025-01-13T18:58:57","date_gmt":"2025-01-13T10:58:57","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1159947.html"},"modified":"2025-01-13T18:59:00","modified_gmt":"2025-01-13T10:59:00","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e5%92%8c%e4%bd%bf%e7%94%a8%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1159947.html","title":{"rendered":"Python\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25201532\/45221f53-e44f-434e-8911-5b2675d72158.webp\" alt=\"Python\u5982\u4f55\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570\" \/><\/p>\n<p><p> <strong>Python\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528def\u5173\u952e\u5b57\u5b9a\u4e49\u51fd\u6570\u3001\u901a\u8fc7\u53c2\u6570\u4f20\u9012\u6570\u636e\u3001\u4f7f\u7528return\u8bed\u53e5\u8fd4\u56de\u7ed3\u679c\u3002<\/strong> \u4f8b\u5982\uff0c\u5728Python\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\uff0c\u7136\u540e\u5728\u51fd\u6570\u5185\u90e8\u7f16\u5199\u5177\u4f53\u7684\u903b\u8f91\u4ee3\u7801\u3002\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u53c2\u6570\uff0c\u8fd9\u6837\u53ef\u4ee5\u4f7f\u5f97\u51fd\u6570\u66f4\u52a0\u7075\u6d3b\u548c\u901a\u7528\u3002\u901a\u8fc7<code>return<\/code>\u8bed\u53e5\uff0c\u51fd\u6570\u53ef\u4ee5\u5c06\u7ed3\u679c\u8fd4\u56de\u7ed9\u8c03\u7528\u8005\u3002<\/p>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b9a\u4e49\u4e00\u4e2a\u8ba1\u7b97\u4e24\u4e2a\u6570\u4e4b\u548c\u7684\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u4f20\u9012\u4e24\u4e2a\u53c2\u6570\uff0c\u5e76\u63a5\u6536\u8fd4\u56de\u7684\u7ed3\u679c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result = add(3, 5)<\/p>\n<p>print(result)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecdPython\u4e2d\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570\u7684\u5177\u4f53\u65b9\u6cd5\u548c\u6280\u5de7\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u5b9a\u4e49\u51fd\u6570<\/strong><\/h2>\n<p><h2>1\u3001\u4f7f\u7528def\u5173\u952e\u5b57<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5b9a\u4e49\u51fd\u6570\u7684\u4e3b\u8981\u65b9\u5f0f\u662f\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\u3002\u51fd\u6570\u5b9a\u4e49\u5305\u62ec\u51fd\u6570\u540d\u3001\u53c2\u6570\u5217\u8868\uff08\u53ef\u9009\uff09\u548c\u51fd\u6570\u4f53\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\u5b9a\u4e49\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet():<\/p>\n<p>    print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a<code>greet<\/code>\u7684\u51fd\u6570\uff0c\u8c03\u7528\u65f6\u4f1a\u8f93\u51fa&quot;Hello, World!&quot;\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c<\/h2>\n<\/p>\n<p><p>\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u53c2\u6570\uff0c\u5e76\u901a\u8fc7<code>return<\/code>\u8bed\u53e5\u8fd4\u56de\u7ed3\u679c\u3002\u53c2\u6570\u53ef\u4ee5\u4f7f\u51fd\u6570\u66f4\u52a0\u7075\u6d3b\u548c\u901a\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>add<\/code>\u51fd\u6570\u63a5\u53d7\u4e24\u4e2a\u53c2\u6570<code>a<\/code>\u548c<code>b<\/code>\uff0c\u5e76\u8fd4\u56de\u5b83\u4eec\u7684\u548c\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u9ed8\u8ba4\u53c2\u6570\u503c<\/h2>\n<\/p>\n<p><p>\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u4e3a\u53c2\u6570\u6307\u5b9a\u9ed8\u8ba4\u503c\uff0c\u8fd9\u6837\u5728\u8c03\u7528\u51fd\u6570\u65f6\u5982\u679c\u6ca1\u6709\u4f20\u9012\u53c2\u6570\uff0c\u51fd\u6570\u4f1a\u4f7f\u7528\u9ed8\u8ba4\u503c\uff1a<\/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><\/code><\/pre>\n<\/p>\n<p><p>\u8c03\u7528<code>greet()<\/code>\u65f6\uff0c\u4f1a\u8f93\u51fa&quot;Hello, World!&quot;\uff1b\u8c03\u7528<code>greet(&quot;Alice&quot;)<\/code>\u65f6\uff0c\u4f1a\u8f93\u51fa&quot;Hello, Alice!&quot;\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001\u51fd\u6570\u8c03\u7528<\/strong><\/h2>\n<p><h2>1\u3001\u4f4d\u7f6e\u53c2\u6570<\/h2>\n<\/p>\n<p><p>\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u6309\u53c2\u6570\u7684\u4f4d\u7f6e\u4f20\u9012\u53c2\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result = add(3, 5)<\/p>\n<p>print(result)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u5173\u952e\u5b57\u53c2\u6570<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u4f4d\u7f6e\u53c2\u6570\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5173\u952e\u5b57\u53c2\u6570\u6765\u8c03\u7528\u51fd\u6570\uff0c\u8fd9\u6837\u53ef\u4ee5\u660e\u786e\u6307\u5b9a\u6bcf\u4e2a\u53c2\u6570\u7684\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result = add(a=3, b=5)<\/p>\n<p>print(result)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3\u3001\u6df7\u5408\u4f7f\u7528\u53c2\u6570<\/h2>\n<\/p>\n<p><p>\u5728\u8c03\u7528\u51fd\u6570\u65f6\uff0c\u53ef\u4ee5\u6df7\u5408\u4f7f\u7528\u4f4d\u7f6e\u53c2\u6570\u548c\u5173\u952e\u5b57\u53c2\u6570\uff0c\u4f46\u4f4d\u7f6e\u53c2\u6570\u5fc5\u987b\u4f4d\u4e8e\u5173\u952e\u5b57\u53c2\u6570\u4e4b\u524d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result = add(3, b=5)<\/p>\n<p>print(result)  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e09\u3001\u51fd\u6570\u7684\u9ad8\u7ea7\u7528\u6cd5<\/strong><\/h2>\n<p><h2>1\u3001\u53ef\u53d8\u53c2\u6570<\/h2>\n<\/p>\n<p><p>Python\u5141\u8bb8\u51fd\u6570\u63a5\u53d7\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\uff0c\u4f7f\u7528<code>*args<\/code>\u548c<code>kwargs<\/code>\u6765\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def sum_all(*args):<\/p>\n<p>    return sum(args)<\/p>\n<p>print(sum_all(1, 2, 3, 4))  # \u8f93\u51fa 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>*args<\/code>\u4f1a\u5c06\u6240\u6709\u4f4d\u7f6e\u53c2\u6570\u6253\u5305\u6210\u4e00\u4e2a\u5143\u7ec4\uff1b<code>kwargs<\/code>\u4f1a\u5c06\u6240\u6709\u5173\u952e\u5b57\u53c2\u6570\u6253\u5305\u6210\u4e00\u4e2a\u5b57\u5178\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def print_info(kwargs):<\/p>\n<p>    for key, value in kwargs.items():<\/p>\n<p>        print(f&quot;{key}: {value}&quot;)<\/p>\n<p>print_info(name=&quot;Alice&quot;, age=30)  # \u8f93\u51fa name: Alice, age: 30<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u533f\u540d\u51fd\u6570<\/h2>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u51fd\u6570\uff0cPython\u8fd8\u652f\u6301\u4f7f\u7528<code>lambda<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u533f\u540d\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">add = lambda a, b: a + b<\/p>\n<p>print(add(3, 5))  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u533f\u540d\u51fd\u6570\u901a\u5e38\u7528\u4e8e\u7b80\u5355\u7684\u64cd\u4f5c\uff0c\u7279\u522b\u662f\u5728\u9700\u8981\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u65f6\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u9012\u5f52\u51fd\u6570<\/h2>\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\u901a\u5e38\u7528\u4e8e\u89e3\u51b3\u5206\u800c\u6cbb\u4e4b\u7684\u95ee\u9898\uff0c\u4f8b\u5982\u8ba1\u7b97\u9636\u4e58\uff1a<\/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<h2><strong>\u56db\u3001\u51fd\u6570\u7684\u4f5c\u7528\u57df\u548c\u95ed\u5305<\/strong><\/h2>\n<p><h2>1\u3001\u4f5c\u7528\u57df<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u51b3\u5b9a\u4e86\u53d8\u91cf\u5728\u54ea\u4e9b\u5730\u65b9\u53ef\u4ee5\u88ab\u8bbf\u95ee\u3002\u5c40\u90e8\u53d8\u91cf\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\uff0c\u53ea\u80fd\u5728\u51fd\u6570\u5185\u90e8\u8bbf\u95ee\uff1b\u5168\u5c40\u53d8\u91cf\u5728\u51fd\u6570\u5916\u90e8\u5b9a\u4e49\uff0c\u53ef\u4ee5\u5728\u6574\u4e2a\u6a21\u5757\u4e2d\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 10  # \u5168\u5c40\u53d8\u91cf<\/p>\n<p>def func():<\/p>\n<p>    x = 5  # \u5c40\u90e8\u53d8\u91cf<\/p>\n<p>    print(x)  # \u8f93\u51fa 5<\/p>\n<p>func()<\/p>\n<p>print(x)  # \u8f93\u51fa 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528<code>global<\/code>\u5173\u952e\u5b57\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u90e8\u4fee\u6539\u5168\u5c40\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">x = 10<\/p>\n<p>def func():<\/p>\n<p>    global x<\/p>\n<p>    x = 5<\/p>\n<p>func()<\/p>\n<p>print(x)  # \u8f93\u51fa 5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u95ed\u5305<\/h2>\n<\/p>\n<p><p>\u95ed\u5305\u662f\u6307\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u51fd\u6570\u53ef\u4ee5\u5f15\u7528\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\u3002\u5373\u4f7f\u5916\u90e8\u51fd\u6570\u5df2\u7ecf\u8fd4\u56de\uff0c\u5185\u90e8\u51fd\u6570\u4ecd\u7136\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u4e9b\u53d8\u91cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def outer_func(x):<\/p>\n<p>    def inner_func(y):<\/p>\n<p>        return x + y<\/p>\n<p>    return inner_func<\/p>\n<p>add_10 = outer_func(10)<\/p>\n<p>print(add_10(5))  # \u8f93\u51fa 15<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>inner_func<\/code>\u662f\u4e00\u4e2a\u95ed\u5305\uff0c\u5b83\u5f15\u7528\u4e86<code>outer_func<\/code>\u7684\u53d8\u91cf<code>x<\/code>\u3002<\/p>\n<\/p>\n<h2><strong>\u4e94\u3001\u88c5\u9970\u5668<\/strong><\/h2>\n<p><p>\u88c5\u9970\u5668\u662fPython\u7684\u4e00\u79cd\u9ad8\u7ea7\u7279\u6027\uff0c\u7528\u4e8e\u5728\u51fd\u6570\u6267\u884c\u524d\u540e\u6dfb\u52a0\u989d\u5916\u7684\u529f\u80fd\u3002\u88c5\u9970\u5668\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u51fd\u6570\uff0c\u5b83\u63a5\u6536\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u5b9a\u4e49\u88c5\u9970\u5668<\/h2>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u88c5\u9970\u5668\u793a\u4f8b\uff1a<\/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<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c<code>my_decorator<\/code>\u662f\u4e00\u4e2a\u88c5\u9970\u5668\uff0c\u5b83\u5728<code>say_hello<\/code>\u51fd\u6570\u6267\u884c\u524d\u540e\u6dfb\u52a0\u4e86\u989d\u5916\u7684\u6253\u5370\u8bed\u53e5\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u88c5\u9970\u5668\u7684\u5e94\u7528<\/h2>\n<\/p>\n<p><p>\u88c5\u9970\u5668\u5e7f\u6cdb\u5e94\u7528\u4e8e\u65e5\u5fd7\u8bb0\u5f55\u3001\u6027\u80fd\u76d1\u63a7\u3001\u6743\u9650\u9a8c\u8bc1\u7b49\u573a\u666f\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8bb0\u5f55\u51fd\u6570\u6267\u884c\u65f6\u95f4\u7684\u88c5\u9970\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>def timer_decorator(func):<\/p>\n<p>    def wrapper(*args, kwargs):<\/p>\n<p>        start_time = time.time()<\/p>\n<p>        result = func(*args, kwargs)<\/p>\n<p>        end_time = time.time()<\/p>\n<p>        print(f&quot;Function {func.__name__} took {end_time - start_time} seconds to execute.&quot;)<\/p>\n<p>        return result<\/p>\n<p>    return wrapper<\/p>\n<p>@timer_decorator<\/p>\n<p>def slow_function():<\/p>\n<p>    time.sleep(2)<\/p>\n<p>    print(&quot;Function finished.&quot;)<\/p>\n<p>slow_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>timer_decorator<\/code>\u88c5\u9970\u5668\u8bb0\u5f55\u4e86<code>slow_function<\/code>\u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\u3002<\/p>\n<\/p>\n<h2><strong>\u516d\u3001\u51fd\u6570\u7684\u7c7b\u578b\u6ce8\u89e3<\/strong><\/h2>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0cPython\u5141\u8bb8\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\u6dfb\u52a0\u7c7b\u578b\u6ce8\u89e3\u3002\u7c7b\u578b\u6ce8\u89e3\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u548c\u5de5\u5177\u66f4\u597d\u5730\u7406\u89e3\u51fd\u6570\u7684\u53c2\u6570\u548c\u8fd4\u56de\u503c\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u53c2\u6570\u7c7b\u578b\u6ce8\u89e3<\/h2>\n<\/p>\n<p><p>\u5728\u51fd\u6570\u5b9a\u4e49\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5192\u53f7<code>:<\/code>\u4e3a\u53c2\u6570\u6dfb\u52a0\u7c7b\u578b\u6ce8\u89e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name: str):<\/p>\n<p>    print(f&quot;Hello, {name}!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u53c2\u6570<code>name<\/code>\u7684\u7c7b\u578b\u88ab\u6ce8\u89e3\u4e3a\u5b57\u7b26\u4e32<code>str<\/code>\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u8fd4\u56de\u503c\u7c7b\u578b\u6ce8\u89e3<\/h2>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u7bad\u5934<code>-&gt;<\/code>\u4e3a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u6dfb\u52a0\u7c7b\u578b\u6ce8\u89e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a: int, b: int) -&gt; int:<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u51fd\u6570<code>add<\/code>\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u88ab\u6ce8\u89e3\u4e3a\u6574\u6570<code>int<\/code>\u3002<\/p>\n<\/p>\n<p><h2>3\u3001\u7c7b\u578b\u68c0\u67e5\u5de5\u5177<\/h2>\n<\/p>\n<p><p>\u867d\u7136\u7c7b\u578b\u6ce8\u89e3\u4e0d\u4f1a\u5f71\u54cd\u4ee3\u7801\u7684\u8fd0\u884c\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528\u7c7b\u578b\u68c0\u67e5\u5de5\u5177\uff08\u5982<code>mypy<\/code>\uff09\u6765\u9759\u6001\u68c0\u67e5\u4ee3\u7801\u4e2d\u7684\u7c7b\u578b\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u4f1a\u88ab<code>mypy<\/code>\u68c0\u6d4b\u5230\u7c7b\u578b\u9519\u8bef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a: int, b: int) -&gt; int:<\/p>\n<p>    return a + b<\/p>\n<p>result = add(3, &quot;5&quot;)  # &quot;5&quot; \u4e0d\u662f\u6574\u6570\uff0c\u7c7b\u578b\u9519\u8bef<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528\u7c7b\u578b\u68c0\u67e5\u5de5\u5177\u53ef\u4ee5\u5728\u5f00\u53d1\u9636\u6bb5\u53d1\u73b0\u6f5c\u5728\u7684\u7c7b\u578b\u9519\u8bef\uff0c\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf\u3002<\/p>\n<\/p>\n<h2><strong>\u4e03\u3001\u51fd\u6570\u5f0f\u7f16\u7a0b<\/strong><\/h2>\n<p><p>Python\u652f\u6301\u51fd\u6570\u5f0f\u7f16\u7a0b\u8303\u5f0f\uff0c\u5141\u8bb8\u5c06\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u7ed9\u5176\u4ed6\u51fd\u6570\uff0c\u8fd4\u56de\u51fd\u6570\u4f5c\u4e3a\u7ed3\u679c\uff0c\u4ee5\u53ca\u4f7f\u7528\u9ad8\u9636\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u9ad8\u9636\u51fd\u6570<\/h2>\n<\/p>\n<p><p>\u9ad8\u9636\u51fd\u6570\u662f\u6307\u63a5\u53d7\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u6216\u8fd4\u56de\u51fd\u6570\u7684\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def apply_func(func, value):<\/p>\n<p>    return func(value)<\/p>\n<p>def square(x):<\/p>\n<p>    return x * x<\/p>\n<p>result = apply_func(square, 5)<\/p>\n<p>print(result)  # \u8f93\u51fa 25<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>apply_func<\/code>\u662f\u4e00\u4e2a\u9ad8\u9636\u51fd\u6570\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u51fd\u6570<code>func<\/code>\u548c\u4e00\u4e2a\u503c<code>value<\/code>\uff0c\u5e76\u8fd4\u56de<code>func(value)<\/code>\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h2>2\u3001\u5e38\u89c1\u7684\u9ad8\u9636\u51fd\u6570<\/h2>\n<\/p>\n<p><p>Python\u5185\u7f6e\u4e86\u4e00\u4e9b\u5e38\u89c1\u7684\u9ad8\u9636\u51fd\u6570\uff0c\u5982<code>map<\/code>\u3001<code>filter<\/code>\u548c<code>reduce<\/code>\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>map<\/code>\u51fd\u6570\u5e94\u7528\u4e00\u4e2a\u51fd\u6570\u5230\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3, 4]<\/p>\n<p>squared_numbers = map(lambda x: x * x, numbers)<\/p>\n<p>print(list(squared_numbers))  # \u8f93\u51fa [1, 4, 9, 16]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>filter<\/code>\u51fd\u6570\u8fc7\u6ee4\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u5143\u7d20\uff0c\u8fd4\u56de\u6ee1\u8db3\u6761\u4ef6\u7684\u5143\u7d20\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3, 4]<\/p>\n<p>even_numbers = filter(lambda x: x % 2 == 0, numbers)<\/p>\n<p>print(list(even_numbers))  # \u8f93\u51fa [2, 4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>reduce<\/code>\u51fd\u6570\u5c06\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u5143\u7d20\u5f52\u7ea6\u4e3a\u4e00\u4e2a\u5355\u4e00\u7684\u503c\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">from functools import reduce<\/p>\n<p>numbers = [1, 2, 3, 4]<\/p>\n<p>sum_of_numbers = reduce(lambda x, y: x + y, numbers)<\/p>\n<p>print(sum_of_numbers)  # \u8f93\u51fa 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3\u3001\u95ed\u5305\u548c\u67ef\u91cc\u5316<\/h2>\n<\/p>\n<p><p>\u95ed\u5305\u548c\u67ef\u91cc\u5316\u662f\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\u7684\u4e24\u4e2a\u91cd\u8981\u6982\u5ff5\u3002<\/p>\n<\/p>\n<ul>\n<li>\u95ed\u5305\uff1a\u95ed\u5305\u662f\u6307\u5728\u51fd\u6570\u5185\u90e8\u5b9a\u4e49\u7684\u51fd\u6570\u53ef\u4ee5\u5f15\u7528\u5916\u90e8\u51fd\u6570\u7684\u53d8\u91cf\u3002\u5373\u4f7f\u5916\u90e8\u51fd\u6570\u5df2\u7ecf\u8fd4\u56de\uff0c\u5185\u90e8\u51fd\u6570\u4ecd\u7136\u53ef\u4ee5\u8bbf\u95ee\u8fd9\u4e9b\u53d8\u91cf\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">def make_adder(x):<\/p>\n<p>    def adder(y):<\/p>\n<p>        return x + y<\/p>\n<p>    return adder<\/p>\n<p>add_10 = make_adder(10)<\/p>\n<p>print(add_10(5))  # \u8f93\u51fa 15<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li>\u67ef\u91cc\u5316\uff1a\u67ef\u91cc\u5316\u662f\u5c06\u4e00\u4e2a\u63a5\u53d7\u591a\u4e2a\u53c2\u6570\u7684\u51fd\u6570\u8f6c\u6362\u4e3a\u4e00\u7cfb\u5217\u63a5\u53d7\u5355\u4e2a\u53c2\u6570\u7684\u51fd\u6570\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u67ef\u91cc\u5316\u793a\u4f8b\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">def curry_add(a):<\/p>\n<p>    def add_b(b):<\/p>\n<p>        return a + b<\/p>\n<p>    return add_b<\/p>\n<p>add_5 = curry_add(5)<\/p>\n<p>print(add_5(3))  # \u8f93\u51fa 8<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u516b\u3001\u5e38\u89c1\u7684\u5185\u7f6e\u51fd\u6570<\/strong><\/h2>\n<p><p>Python\u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u51fd\u6570\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u800c\u65e0\u9700\u5bfc\u5165\u4efb\u4f55\u6a21\u5757\u3002\u8fd9\u4e9b\u5185\u7f6e\u51fd\u6570\u6db5\u76d6\u4e86\u5e7f\u6cdb\u7684\u529f\u80fd\uff0c\u4ece\u6570\u5b66\u8fd0\u7b97\u5230\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><h2>1\u3001\u6570\u5b66\u51fd\u6570<\/h2>\n<\/p>\n<p><p>Python\u5185\u7f6e\u4e86\u4e00\u4e9b\u5e38\u89c1\u7684\u6570\u5b66\u51fd\u6570\uff0c\u5982<code>abs<\/code>\u3001<code>max<\/code>\u3001<code>min<\/code>\u3001<code>sum<\/code>\u7b49\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>abs<\/code>\uff1a\u8fd4\u56de\u4e00\u4e2a\u6570\u7684\u7edd\u5bf9\u503c\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(abs(-5))  # \u8f93\u51fa 5<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>max<\/code>\uff1a\u8fd4\u56de\u4e00\u7ec4\u6570\u4e2d\u7684\u6700\u5927\u503c\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(max(1, 2, 3, 4))  # \u8f93\u51fa 4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>min<\/code>\uff1a\u8fd4\u56de\u4e00\u7ec4\u6570\u4e2d\u7684\u6700\u5c0f\u503c\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(min(1, 2, 3, 4))  # \u8f93\u51fa 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>sum<\/code>\uff1a\u8fd4\u56de\u4e00\u7ec4\u6570\u7684\u548c\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(sum([1, 2, 3, 4]))  # \u8f93\u51fa 10<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2\u3001\u7c7b\u578b\u8f6c\u6362\u51fd\u6570<\/h2>\n<\/p>\n<p><p>Python\u5185\u7f6e\u4e86\u4e00\u4e9b\u7c7b\u578b\u8f6c\u6362\u51fd\u6570\uff0c\u5982<code>int<\/code>\u3001<code>float<\/code>\u3001<code>str<\/code>\u3001<code>list<\/code>\u7b49\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>int<\/code>\uff1a\u5c06\u4e00\u4e2a\u503c\u8f6c\u6362\u4e3a\u6574\u6570\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(int(&quot;123&quot;))  # \u8f93\u51fa 123<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>float<\/code>\uff1a\u5c06\u4e00\u4e2a\u503c\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(float(&quot;123.45&quot;))  # \u8f93\u51fa 123.45<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>str<\/code>\uff1a\u5c06\u4e00\u4e2a\u503c\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(str(123))  # \u8f93\u51fa &quot;123&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>list<\/code>\uff1a\u5c06\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5217\u8868\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(list(&quot;abc&quot;))  # \u8f93\u51fa [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>3\u3001\u8fed\u4ee3\u51fd\u6570<\/h2>\n<\/p>\n<p><p>Python\u5185\u7f6e\u4e86\u4e00\u4e9b\u8fed\u4ee3\u51fd\u6570\uff0c\u5982<code>range<\/code>\u3001<code>enumerate<\/code>\u3001<code>zip<\/code>\u7b49\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>range<\/code>\uff1a\u751f\u6210\u4e00\u4e2a\u8303\u56f4\u5185\u7684\u6570\u5217\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">print(list(range(5)))  # \u8f93\u51fa [0, 1, 2, 3, 4]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>enumerate<\/code>\uff1a\u8fd4\u56de\u4e00\u4e2a\u679a\u4e3e\u5bf9\u8c61\uff0c\u53ef\u4ee5\u540c\u65f6\u83b7\u53d6\u5143\u7d20\u7684\u7d22\u5f15\u548c\u503c\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">for index, value in enumerate([&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]):<\/p>\n<p>    print(index, value)<\/p>\n<h2><strong>\u8f93\u51fa\uff1a<\/strong><\/h2>\n<h2><strong>0 a<\/strong><\/h2>\n<h2><strong>1 b<\/strong><\/h2>\n<h2><strong>2 c<\/strong><\/h2>\n<p><\/code><\/pre>\n<\/p>\n<ul>\n<li><code>zip<\/code>\uff1a\u5c06\u591a\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u6253\u5305\u6210\u4e00\u4e2a\u8fed\u4ee3\u5668\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\">numbers = [1, 2, 3]<\/p>\n<p>letters = [&#39;a&#39;, &#39;b&#39;, &#39;c&#39;]<\/p>\n<p>print(list(zip(numbers, letters)))  # \u8f93\u51fa [(1, &#39;a&#39;), (2, &#39;b&#39;), (3, &#39;c&#39;)]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u4e5d\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>Python\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570\u7684\u65b9\u5f0f\u975e\u5e38\u7075\u6d3b\u548c\u5f3a\u5927\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u51fd\u6570\u5b9a\u4e49\uff0c\u8fd8\u662f\u9ad8\u7ea7\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0cPython\u90fd\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u7279\u6027\u3002\u901a\u8fc7\u638c\u63e1\u8fd9\u4e9b\u6280\u5de7\uff0c\u53ef\u4ee5\u7f16\u5199\u51fa\u66f4\u52a0\u9ad8\u6548\u3001\u53ef\u8bfb\u548c\u53ef\u7ef4\u62a4\u7684\u4ee3\u7801\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u7406\u89e3\u548c\u4f7f\u7528Python\u51fd\u6570\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\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u4f7f\u7528<code>def<\/code>\u5173\u952e\u5b57\uff0c\u540e\u8ddf\u51fd\u6570\u540d\u548c\u62ec\u53f7\u5185\u7684\u53c2\u6570\u3002\u51fd\u6570\u4f53\u9700\u8981\u7f29\u8fdb\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">def greet(name):\n    print(f&quot;Hello, {name}!&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u53c2\u6570<code>name<\/code>\uff0c\u5e76\u6253\u5370\u51fa\u95ee\u5019\u8bed\u3002\u8981\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u53ea\u9700\u4f7f\u7528\u51fd\u6570\u540d\u5e76\u4f20\u5165\u6240\u9700\u7684\u53c2\u6570\uff0c\u4f8b\u5982\uff1a<code>greet(&quot;Alice&quot;)<\/code>\u3002<\/p>\n<p><strong>\u51fd\u6570\u53ef\u4ee5\u6709\u9ed8\u8ba4\u53c2\u6570\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u5141\u8bb8\u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\u8bbe\u7f6e\u9ed8\u8ba4\u53c2\u6570\u3002\u8fd9\u4f7f\u5f97\u8c03\u7528\u51fd\u6570\u65f6\u53ef\u4ee5\u9009\u62e9\u6027\u5730\u7701\u7565\u67d0\u4e9b\u53c2\u6570\u3002\u5982\u679c\u7701\u7565\u4e86\u8fd9\u4e9b\u53c2\u6570\uff0c\u51fd\u6570\u5c06\u4f7f\u7528\u9ed8\u8ba4\u503c\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">def greet(name=&quot;Guest&quot;):\n    print(f&quot;Hello, {name}!&quot;)\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c\u8c03\u7528<code>greet()<\/code>\uff0c\u8f93\u51fa\u5c06\u662f<code>Hello, Guest!<\/code>\uff0c\u5982\u679c\u8c03\u7528<code>greet(&quot;Alice&quot;)<\/code>\uff0c\u5219\u8f93\u51fa\u5c06\u662f<code>Hello, Alice!<\/code>\u3002<\/p>\n<p><strong>\u5982\u4f55\u8fd4\u56de\u503c\u800c\u4e0d\u4ec5\u4ec5\u662f\u6253\u5370\u8f93\u51fa\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>return<\/code>\u8bed\u53e5\u4ece\u51fd\u6570\u4e2d\u8fd4\u56de\u503c\u3002\u8fd4\u56de\u503c\u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u6570\u5b57\u3001\u5b57\u7b26\u4e32\u6216\u5217\u8868\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">def add(a, b):\n    return a + b\n<\/code><\/pre>\n<p>\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u5e76\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\uff0c\u53ef\u4ee5\u5f97\u5230\u8ba1\u7b97\u7ed3\u679c\uff1a<code>result = add(5, 3)<\/code>\uff0c\u6b64\u65f6<code>result<\/code>\u7684\u503c\u4e3a<code>8<\/code>\u3002\u4f7f\u7528<code>return<\/code>\u8bed\u53e5\u4f7f\u5f97\u51fd\u6570\u66f4\u52a0\u7075\u6d3b\uff0c\u80fd\u591f\u5728\u4e0d\u540c\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u8fd4\u56de\u7684\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5b9a\u4e49\u548c\u4f7f\u7528\u51fd\u6570\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528def\u5173\u952e\u5b57\u5b9a\u4e49\u51fd\u6570\u3001\u901a\u8fc7\u53c2\u6570\u4f20\u9012\u6570\u636e\u3001\u4f7f\u7528return\u8bed\u53e5\u8fd4\u56de\u7ed3\u679c\u3002 [&hellip;]","protected":false},"author":3,"featured_media":1159957,"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\/1159947"}],"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=1159947"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1159947\/revisions"}],"predecessor-version":[{"id":1159961,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1159947\/revisions\/1159961"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1159957"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1159947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1159947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1159947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}