{"id":269057,"date":"2021-01-10T01:05:43","date_gmt":"2021-01-09T17:05:43","guid":{"rendered":"http:\/\/4563.org\/?p=269057"},"modified":"2021-01-10T01:05:43","modified_gmt":"2021-01-09T17:05:43","slug":"sum-%e7%b1%bb%e8%81%9a%e5%90%88%e5%87%bd%e6%95%b0%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=269057","title":{"rendered":"sum \u7c7b\u805a\u5408\u51fd\u6570\u600e\u4e48\u7528?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  sum \u7c7b\u805a\u5408\u51fd\u6570\u600e\u4e48\u7528?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : fanqieipnet <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        sum \u7c7b\u805a\u5408\u51fd\u6570\u600e\u4e48\u7528?\u4eca\u5929\u756a\u8304\u52a0\u901f\u5c31\u6765\u5206\u4eab\u4e00\u4e0b\u3002<\/p>\n<p>\u3000\u3000 Python \u4e2d\u7684\u805a\u5408\u7c7b\u51fd\u6570 sum,min,max \u7b2c\u4e00\u4e2a\u53c2\u6570\u662f iterable \u7c7b\u578b\uff0c\u4e00\u822c\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>\u3000\u3000 a = [4,2,5,1]<\/p>\n<p>\u3000\u3000 sum([i+1 for i in a]) # 16<\/p>\n<p>\u3000\u3000\u4f7f\u7528\u5217\u8868\u751f\u6210\u5f0f[i+1 for i in a]\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e0e a \u4e00\u6837\u7684\u4e34\u65f6\u5217\u8868\uff0c\u8fd9\u6b65\u5b8c\u6210\u540e\uff0c\u518d\u505a sum \u805a\u5408\u3002<\/p>\n<p>\u3000\u3000\u8bd5\u60f3\u5982\u679c\u4f60\u7684\u6570\u7ec4 a \u957f\u5ea6\u662f\u767e\u4e07\u7ea7\uff0c\u518d\u521b\u5efa\u4e00\u4e2a\u8fd9\u6837\u7684\u4e34\u65f6\u5217\u8868\u5c31\u5f88\u4e0d\u5212\u7b97\uff0c\u6700\u597d\u662f\u4e00\u8fb9\u7b97\u4e00\u8fb9\u805a\u5408\uff0c\u7a0d\u6539\u52a8\u4e3a\u5982\u4e0b\uff1a<\/p>\n<p>\u3000\u3000 a = [4,2,5,1]<\/p>\n<p>\u3000\u3000 sum(i+1 for i in a) # 16<\/p>\n<p>\u3000\u3000\u6b64\u65f6 i+1 for i in a \u662f(i+1 for i in a)\u7684\u7b80\u5199\uff0c\u5f97\u5230\u4e00\u4e2a\u751f\u6210\u5668(generator)\u5bf9\u8c61\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>\u3000\u3000 In [8]:(i+1 for i in a)<\/p>\n<p>\u3000\u3000 OUT [8]: at 0x000002AC7FFA8CF0&gt;<\/p>\n<p>\u3000\u3000\u751f\u6210\u5668\u6bcf\u8fed\u4ee3\u4e00\u6b65\u5410\u51fa(yield)\u4e00\u4e2a\u5143\u7d20\u5e76\u8ba1\u7b97\u548c\u805a\u5408\u540e\uff0c\u8fdb\u5165\u4e0b\u4e00\u6b21\u8fed\u4ee3\uff0c\u76f4\u5230\u7ec8\u70b9\u3002      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>sum \u7c7b\u805a\u5408\u51fd\u6570\u600e\u4e48\u7528? \u8cc7\u6df1\u5927&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/269057"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=269057"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/269057\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=269057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=269057"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=269057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}