{"id":213,"date":"2018-10-08T22:00:38","date_gmt":"2018-10-08T14:00:38","guid":{"rendered":"http:\/\/develop-note.com\/blog\/?p=213"},"modified":"2023-05-10T05:59:45","modified_gmt":"2023-05-09T21:59:45","slug":"2019ironman-flask-restful-day07","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2018\/10\/08\/2019ironman-flask-restful-day07\/","title":{"rendered":"\u7b2c\u5341\u5c46\u9435\u4eba\u8cfd flask-restful DAY07-\u641e\u61c2Python\u7684\u65b9\u6cd5"},"content":{"rendered":"<h1>\u70ba\u4ec0\u9ebc\u8981\u7528\u65b9\u6cd5<\/h1>\n<p>\u76f8\u4fe1\u8b80\u8005\u64b0\u5beb\u7a0b\u5e8f\u6642\u5e38\u5e38\u6703\u6709\u4e0d\u65b7\u7684\u64b0\u5beb\u4e00\u6a23\u7a0b\u5e8f\u7684\u72c0\u6cc1\uff0c\u4f46\u662f\u9700\u8981\u7dad\u8b77\u7a0b\u5e8f\u6642\u901a\u5e38\u6703\u9700\u8981\u4fee\u6539\u8a31\u591a\u5730\u65b9\uff0c\u800c\u4e14\u5e38\u5e38\u6703\u6709\u6240\u907a\u6f0f\uff0c\u9019\u6642\u5019\u8b80\u8005\u5011\u90fd\u6703\u60f3\u8aaa\u5982\u679c\u4fee\u6539\u4e00\u500b\u5730\u65b9\u5c31\u53ef\u4ee5\u66f4\u65b0\u6240\u6709\u7684\u5730\u65b9\u7684\u8a71\u4e0d\u77e5\u9053\u8a72\u6709\u591a\u597d\u3002\u518d\u4f86\u4e0d\u65b7\u5beb\u540c\u6a23\u7684\u7a0b\u5e8f\u5c31\u7b97\u5beb\u7684\u4eba\u4e0d\u81a9\uff0cReview\u7684\u4eba\u4e5f\u6703\u81a9\uff0c\u56e0\u6b64\u8981\u5982\u4f55\u91cd\u8907\u5229\u7528\u5beb\u904e\u7684\u7a0b\u5e8f\u5c31\u986f\u5f97\u91cd\u8981\u3002\u4ee5\u4e0a\u662f\u5927\u5bb6\u8b80\u8005\u4ee5\u53ca\u7b46\u8005\u672c\u4eba\u7684\u60f3\u6cd5\uff0c\u5176\u5be6\u8edf\u9ad4\u958b\u767c\u7684\u5927\u795e\u4e5f\u6709\u76f8\u540c\u7684\u60f3\u6cd5\uff0c\u6240\u4ee5\u63d0\u51fa\u4e86\u4e00\u500b<a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E4%B8%80%E6%AC%A1%E4%B8%94%E4%BB%85%E4%B8%80%E6%AC%A1\" rel=\"nofollow noopener\" target=\"_blank\">Dry<\/a>\u7684\u539f\u5247\u3002\u7136\u800c\u8981\u5982\u4f55\u91cd\u8907\u5229\u7528\u6240\u5beb\u7684\u7a0b\u5e8f\u5462\uff0c\u900f\u904e\u65b9\u6cd5\u7684\u64b0\u5beb\u5c31\u662f\u5176\u4e2d\u4e00\u500b\u65b9\u5f0f\u3002<!--more--><\/p>\n<h1>\u65b9\u6cd5\u600e\u9ebc\u64b0\u5beb<\/h1>\n<p>\u5148\u8acb\u8b80\u8005\u5011\u770b\u770b\u4e0b\u5217\u7684\u5f0f\u5b50\uff0c\u900f\u904e\u4e0b\u5217\u5f0f\u5b50\u8b93\u8b80\u8005\u5011\u4e86\u89e3\u8981\u5982\u4f55\u64b0\u5beb\u7b2c\u4e00\u500b\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-python\">def printHelloWorld():\n    print(&#039;Hello World&#039;)<\/code><\/pre>\n<p>\u5982\u6b64\uff0c\u5c31\u5b8c\u6210\u4e86\u8b80\u8005\u5011\u7684\u7b2c\u4e00\u500b\u65b9\u6cd5\uff0c\u529f\u80fd\u662f\u5370\u51faHello World\u7684\u4e00\u500b\u65b9\u6cd5\u3002\u5f9e\u4e0a\u9762\u7684\u5f0f\u5b50\u53ef\u4ee5\u77e5\u9053\u57fa\u672c\u7684\u65b9\u6cd5\u662f\u7531\u5ba3\u544a\u8a5e<code>def<\/code> \u958b\u59cb\uff0c\u5f8c\u9762\u5c3e\u96a8\u7684\u662f<code>printHelloWorld<\/code>\u65b9\u6cd5\u7684\u540d\u7a31\uff0c\u63a5\u4e0b\u4f86<code>( )<\/code>\u5c0f\u62ec\u865f\u5167\u662f\u8f38\u5165\u7684\u53c3\u6578\uff0c\u6700\u5f8c\u7d50\u5c3e\u662f<code>:<\/code>\uff0c\u800c\u65b9\u6cd5\u5be6\u505a\u7684\u5167\u5bb9\u5247\u5728\u7e2e\u6392\u5167\u64b0\u5beb\u3002<\/p>\n<h1>\u5982\u4f55\u8986\u7528<\/h1>\n<p>\u900f\u904e\u4e0a\u8ff0\u65b9\u5f0f\u53ef\u4ee5\u64b0\u5beb\u65b9\u6cd5\uff0c\u4f46\u662f\u9019\u6a23\u5b50\u7684\u65b9\u6cd5\u5982\u4f55\u7528\u5728\u8a31\u591a\u5730\u65b9\u5462\uff0c\u4f8b\u5982\u6bcf\u500b\u7a0b\u5e8f\u6709\u60f3\u8981\u5217\u5370\u51fa\u4f86\u7684\u8a0a\u606f\u8981\u5982\u4f55\u4f7f\u7528\u5462?\u6240\u4ee5\u9019\u6642\u5019\u5c31\u5148\u770b\u770b\u4ee5\u4e0b\u4f8b\u5b50:<\/p>\n<pre><code class=\"language-python\">def sayHiToParam(param):\n    print(&#039;Hi {0}&#039;.format(param))<\/code><\/pre>\n<p>\u9019\u6642\u5019\u8b80\u8005\u5c31\u53ef\u4ee5\u5c07\u4e0d\u540c\u7684\u5730\u65b9\u900f\u904e\u53c3\u6578\u653e\u5728<code>( )<\/code> \u5167\u50b3\u905e\uff0c\u7136\u5f8c\u65b9\u6cd5\u7684\u5be6\u4f5c\u518d\u53d6\u53c3\u6578\u4f7f\u7528\uff0c\u4f8b\u5982\u4e0a\u8ff0\u7684\u4f8b\u5b50\u5c31\u53ef\u4ee5\u8b93\u5176\u4ed6\u4f7f\u7528\u65b9\u6cd5\u7684\u5730\u65b9\u50b3\u905e<code>param<\/code> \u5230\u65b9\u6cd5\u5167\uff0c\u5982\u679c\u4eca\u5929\u9700\u8981\u5c07\u6240\u6709<code>Hi<\/code>\u66f4\u6539\u70ba<code>Hello<\/code>\u53ea\u8981\u4fee\u6539\u9019\u65b9\u6cd5\u5373\u53ef\u3002<\/p>\n<h1>\u9810\u8a2d\u53c3\u6578<\/h1>\n<p>\u6709\u6642\u64b0\u5beb\u7a0b\u5e8f\u6642\u6703\u5e0c\u671b\u7d66\u4f7f\u7528\u8005\u4fbf\u5229\u6027\uff0c\u4f8b\u5982\u6709\u4e9b\u53c3\u6578\u53ef\u4ee5\u5e0c\u671b\u53ef\u4ee5\u7d66\u4e88\u4f7f\u7528\u65b9\u6cd5\u7684\u4eba\u5f48\u6027\uff0c\u4f46\u662f\u4e0d\u9700\u8981\u9019\u5f48\u6027\u7684\u4f7f\u7528\u8005\u53c8\u5e0c\u671b\u7d66\u4ed6\u4fbf\u5229\u6027\uff0c\u6240\u4ee5\u5c31\u53ef\u4ee5\u900f\u904e\u9810\u8a2d\u53c3\u6578\u4f86\u5b8c\u6210\uff0c\u63a5\u4e0b\u4f86\u5c31\u770b\u770b\u751a\u9ebc\u662f\u9810\u8a2d\u53c3\u6578\uff1a<\/p>\n<pre><code class=\"language-python\">def sayParamYear(param, year = 10):\n    print(&quot;I&#039;m {0} and I&#039;m {1} years old&quot;.format(param, year))<\/code><\/pre>\n<p>\u5176\u4e2d\u6211\u5011\u518d\u5b9a\u7fa9\u65b9\u6cd5\u5be6\u5df2\u7d93\u7d66<code>year<\/code>\u9019\u53c3\u6578\u9810\u5b9a\u70ba10\uff0c\u4e0d\u904e\u5916\u90e8\u4f7f\u7528\u8005\u4ea6\u53ef\u4ee5\u50b3\u5165\u53c3\u6578\u4f86\u6539\u8b8ayear\u9019\u8b8a\u6578\u3002\u5118\u7ba1\u9810\u8a2d\u53c3\u6578\u53ef\u4ee5\u7d66\u4e88\u4f7f\u7528\u8005\u4fbf\u5229\u6027\uff0c\u4f46\u662f\u4ed6\u4e5f\u5e36\u4f86\u53e6\u5916\u4e00\u500b\u5751\uff0c\u8acb\u5404\u4f4d\u5148\u770b\u770b\u4ee5\u4e0b\u4f8b\u5b50\uff1a<\/p>\n<pre><code class=\"language-python\">def appendParamToArray(param, array = []):\n    array.append(param)\n    print(array)\n\nappendParamToArray(1)\nappendParamToArray(2)\narr = []\nappendParamToArray(1, arr)\nappendParamToArray(2, arr)<\/code><\/pre>\n<p>\u5404\u4f4d\u8b80\u8005\u731c\u731c\u9019\u6bb5\u7a0b\u5f0f\u7684\u7d50\u679c\u6703\u5370\u51fa\u4ec0\u9ebc\uff0c\u76f8\u4fe1\u8e29\u904e\u5751\u7684\u8b80\u8005\u6703\u9732\u51fa\u6703\u5fc3\u7684\u4e00\u7b11\uff0c\u6c92\u932f\u7b54\u6848\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">[1]\n[1, 2]\n[1]\n[1, 2]<\/code><\/pre>\n<p>\u70ba\u4ec0\u9ebc\u7b54\u6848\u6703\u662f\u9019\u6a23\u5462\uff0c\u76f8\u4fe1\u7b2c\u4e00\u6b21\u4f7f\u7528Python\u7684\u8b80\u8005\u6703\u51fa\u4e4e\u610f\u6599\u5730\u554f\u9019\u554f\u984c\uff0c\u56e0\u70baPython\u7684\u9810\u8a2d\u53c3\u6578\u6709\u500b\u7279\u6027\uff0c\u7576\u57f7\u884c\u5230<code>def<\/code> \u7684\u51fd\u5f0f\u5b9a\u7fa9\u6642\uff0c\u5c31\u5efa\u7acb\u4e86\u7a7a\u4e32\u5217\u7269\u4ef6\u4e26\u8ce6\u4e88<code>array<\/code>\uff0c\u800c\u9019\u500b\u7269\u4ef6\u6703\u4e00\u76f4\u5b58\u5728\uff0c\u5982\u679c\u4f60\u6c92\u6709\u6307\u5b9a<code>array<\/code>\u7684\u4e32\u5217\u7269\u4ef6\u6642\uff0c\u6240\u4f7f\u7528\u7684\u5c31\u4e00\u76f4\u6703\u662f\u4e00\u958b\u59cb\u6307\u5b9a\u7684\u9810\u8a2d\u7a7a\u4e32\u5217\u7269\u4ef6\uff0c\u56e0\u6b64<code>appendParamToArray(2)<\/code> \u6240\u4f7f\u7528\u7684<code>array<\/code>\u5373\u662f<code>appendParamToArray(1)<\/code> \u6240\u7522\u751f\u7684\u7a7a\u4e32\u5217\u7269\u4ef6\uff0c\u800c<code>appendParamToArray(1, arr)<\/code> \u8207<code>appendParamToArray(1, arr)<\/code> \u7528\u7684\u5247\u662f<code>arr = [] <\/code> \u9019\u6642\u7522\u751f\u7684\u4e32\u5217\u7269\u4ef6\uff0c\u6240\u4ee5\u7576\u9810\u8a2d\u53c3\u6578\u9047\u5230\u4e4b\u524d\u7684\u53ef\u8b8a\u578b\u614b\u6642\u5c31\u8981\u7279\u5225\u6ce8\u610f\u4e86\u3002\u4ee5\u4e0b\u9019\u65b9\u6cd5\u53ef\u4ee5\u89e3\u6c7a\u4e0a\u8ff0\u53ef\u8b8a\u578b\u614b\u9810\u8a2d\u53c3\u6578\u7684\u554f\u984c\uff1a<\/p>\n<pre><code class=\"language-python\">def appendParamToArray(param, array = None):\n    if not array:\n        array = []\n    array.append(param)\n    print(array)<\/code><\/pre>\n<p>\u4e0a\u8ff0\u5f0f\u5b50\u5c31\u662f\u5148\u4e0d\u6307\u5b9a\u7a7a\u4e32\u5217\u7d66<code>array<\/code>\uff0c\u76f4\u5230\u65b9\u6cd5\u7684\u6642\u505a\u6aa2\u67e5\u767c\u73fe\u6c92\u6709\u7d66\u4e88<code>array<\/code> \u6642\u624d\u7d66\u4e88\u7a7a\u4e32\u5217\u7269\u4ef6\u3002\u5118\u7ba1\u6b64\u65b9\u6cd5\u53ef\u4ee5\u907f\u514d\u53ef\u8b8a\u578b\u614b\u9810\u8a2d\u53c3\u6578\u7684\u554f\u984c\uff0c\u4f46\u662f\u9084\u662f\u76e1\u91cf\u907f\u514d\u4f7f\u7528\u9810\u8a2d\u53c3\u6578\u7684\u63cf\u8ff0\u518d\u53ef\u8b8a\u578b\u614b\u4e0a\u3002<\/p>\n<h1>\u5c0f\u7d50<\/h1>\n<p>\u7d93\u904e\u4e0a\u8ff0\u7684\u5167\u5bb9\u76f8\u4fe1\u5404\u4f4d\u8b80\u8005\u5c0d\u65bcPython\u7684\u65b9\u6cd5\u6709\u66f4\u9032\u4e00\u6b65\u7684\u8a8d\u8b58\uff0c\u900f\u904e\u65b9\u6cd5\u53ef\u4ee5\u8b93\u7a0b\u5e8f\u8986\u7528\u4e4b\u5916\uff0cOOP\u66f4\u662f\u8b93\u7a0b\u5e8f\u8986\u7528\u66f4\u63d0\u5347\u5230\u53e6\u4e00\u500b\u5883\u754c\uff0c\u6240\u4ee5\u4e0b\u4e00\u7ae0\u5c31\u4f86\u8ac7\u8ac7Python\u7684OOP\uff0c\u656c\u8acb\u671f\u5f85\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u70ba\u4ec0\u9ebc\u8981\u7528\u65b9\u6cd5 \u76f8\u4fe1\u8b80\u8005\u64b0\u5beb\u7a0b\u5e8f\u6642\u5e38\u5e38\u6703\u6709\u4e0d\u65b7\u7684\u64b0\u5beb\u4e00\u6a23\u7a0b\u5e8f\u7684\u72c0\u6cc1\uff0c\u4f46\u662f\u9700\u8981\u7dad\u8b77\u7a0b\u5e8f\u6642\u901a\u5e38\u6703\u9700\u8981\u4fee\u6539\u8a31\u591a\u5730\u65b9\uff0c &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2018\/10\/08\/2019ironman-flask-restful-day07\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u7b2c\u5341\u5c46\u9435\u4eba\u8cfd flask-restful DAY07-\u641e\u61c2Python\u7684\u65b9\u6cd5\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[162,4,5,3],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2018ironman","tag-flask","tag-flask-restful","tag-python"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":34,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":3090,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/213\/revisions\/3090"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}