{"id":3393,"date":"2023-05-18T13:24:30","date_gmt":"2023-05-18T05:24:30","guid":{"rendered":"http:\/\/cnliutz.ipyingshe.net\/?p=3393"},"modified":"2023-05-18T14:03:49","modified_gmt":"2023-05-18T06:03:49","slug":"python%e5%87%bd%e6%95%b0%e8%a3%85%e9%a5%b0%e5%99%a8%e3%80%81%e6%8e%a8%e5%af%bc%e5%99%a8","status":"publish","type":"post","link":"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=3393","title":{"rendered":"python\u51fd\u6570\u88c5\u9970\u5668\u3001\u63a8\u5bfc\u5668\u3001\u751f\u6210\u5668"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#\u88c5\u9970\u56681\ndef doubler(func):\n    def wrapper():\n        return func() * 2\n    return wrapper\n# def get_five():\n#     return 5\n# doubled = doubler(get_five)\n# print(doubled())\n@doubler\ndef get_x():\n    return 10\nprint(\"\u88c5\u9970\u5668\u8c03\u7528\u7ed3\u679c\uff1a\")\nprint(get_x())\n\n#\u88c5\u9970\u56682\ndef my_decorator(func):\n    def wrapper():\n        print(\"Something is happening before the function is called.\")\n        func()\n        print(\"Something is happening after the function is called.\")\n    return wrapper\n\ndef say_hello():\n    print(\"Hello!\")\n\nsay_hello = my_decorator(say_hello)\nsay_hello()\n\n#--------------\u51fd\u6570\u63a8\u5bfc\u5668-----------\nprint(\"\u51fd\u6570\u63a8\u5bfc\u5668\")\nfruits = &#91;'Banana', 'Apple', 'Lime']\nloud_fruits = &#91;fruit.upper() for fruit in fruits]\nprint(loud_fruits)\n\nfruits = &#91;'Banana', 'Apple', 'Lime']\nprint(list(enumerate(fruits)))\n\ndef my_function(fname):\n  print(fname + \" Refsnes\")\n\nmy_function(\"Emil\")\nmy_function(\"Tobias\")\nmy_function(\"Linus\")\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u51fd\u6570\u751f\u6210\u5668\ndef my_range(n):\r\n    i = 0\r\n    while i &lt; n+8:\r\n        yield i*i\r\n        i +=1\r\nfor x in my_range(5):\r\n    print(x)    <\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\u7684\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>0<br>1<br>4<br>9<br>16<br>25<br>36<br>49<br>64<br>81<br>100<br>121<br>144<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f93\u51fa\u7684\u7ed3\u679c\uff1a 0149162536496481100121144<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,10],"tags":[],"class_list":["post-3393","post","type-post","status-publish","format-standard","hentry","category-2","category-python"],"_links":{"self":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3393"}],"version-history":[{"count":2,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3393\/revisions"}],"predecessor-version":[{"id":3396,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3393\/revisions\/3396"}],"wp:attachment":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3393"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}