{"id":433,"date":"2025-01-13T18:47:29","date_gmt":"2025-01-13T10:47:29","guid":{"rendered":"http:\/\/sqtcw.cn\/?p=433"},"modified":"2025-01-13T18:47:29","modified_gmt":"2025-01-13T10:47:29","slug":"python-%e4%b8%ad-print-%e5%92%8c-return-%e7%9a%84%e7%94%a8%e6%b3%95%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"http:\/\/www.cnitw.com\/?p=433","title":{"rendered":"Python \u4e2d\u00a0print\u00a0\u548c\u00a0return\u00a0\u7684\u7528\u6cd5\u793a\u4f8b"},"content":{"rendered":"\n<p>\u4ee5\u4e0b\u662f Python \u4e2d <code>print<\/code> \u548c <code>return<\/code> \u7684\u7528\u6cd5\u793a\u4f8b\uff1a<\/p>\n\n\n\n<p><strong><code>print<\/code> \u7684\u7528\u6cd5<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># print \u7528\u4e8e\u5728\u63a7\u5236\u53f0\u8f93\u51fa\u4fe1\u606f\nprint(\"Hello, World!\")\n\na = 10\nb = 20\nprint(f\"The sum of {a} and {b} is {a + b}.\")<\/code><\/pre>\n\n\n\n<p><strong><code>return<\/code> \u7684\u7528\u6cd5<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def add_numbers(x, y):\n    \"\"\"\n    This function adds two numbers and returns the result.\n\n    Parameters:\n    x (int): The first number.\n    y (int): The second number.\n\n    Returns:\n    int: The sum of the two numbers.\n    \"\"\"\n    return x + y\n\nresult = add_numbers(5, 3)\nprint(result)<\/code><\/pre>\n\n\n\n<p>\u7528\u6cd5\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>print<\/code>\uff1a<\/li>\n\n\n\n<li>\u4e3b\u8981\u7528\u4e8e\u5c06\u4fe1\u606f\u8f93\u51fa\u5230\u63a7\u5236\u53f0\uff0c\u4ee5\u4fbf\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u67e5\u770b\u4e2d\u95f4\u7ed3\u679c\u6216\u8c03\u8bd5\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><code>print<\/code> \u8bed\u53e5\u6267\u884c\u540e\u4e0d\u4f1a\u7ec8\u6b62\u51fd\u6570\u7684\u6267\u884c\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u4e2d\u591a\u6b21\u4f7f\u7528\u3002<\/li>\n\n\n\n<li><code>return<\/code>\uff1a<\/li>\n\n\n\n<li>\u7528\u4e8e\u4ece\u51fd\u6570\u4e2d\u8fd4\u56de\u4e00\u4e2a\u503c\u3002\u5f53\u51fd\u6570\u6267\u884c\u5230 <code>return<\/code> \u8bed\u53e5\u65f6\uff0c\u51fd\u6570\u7acb\u5373\u7ed3\u675f\u5e76\u5c06\u6307\u5b9a\u7684\u503c\u8fd4\u56de\u7ed9\u8c03\u7528\u8005\u3002<\/li>\n\n\n\n<li>\u4e00\u4e2a\u51fd\u6570\u53ef\u4ee5\u6709\u591a\u4e2a <code>return<\/code> \u8bed\u53e5\uff0c\u4f46\u53ea\u6709\u7b2c\u4e00\u4e2a\u88ab\u6267\u884c\u5230\u7684 <code>return<\/code> \u8d77\u4f5c\u7528\uff08\u5728\u4e0d\u540c\u7684\u6761\u4ef6\u5206\u652f\u4e2d\uff09\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u51fd\u6570\u6ca1\u6709\u663e\u5f0f\u7684 <code>return<\/code> \u8bed\u53e5\uff0c\u9ed8\u8ba4\u4f1a\u8fd4\u56de <code>None<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u662f Python \u4e2d print \u548c return \u7684\u7528\u6cd5\u793a\u4f8b\uff1a print \u7684\u7528\u6cd5\uff1a return \u7684\u7528\u6cd5\uff1a \u7528\u6cd5\u8bf4\u660e\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-433","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=433"}],"version-history":[{"count":0,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/433\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}