{"id":237319,"date":"2021-01-01T01:20:56","date_gmt":"2020-12-31T17:20:56","guid":{"rendered":"http:\/\/4563.org\/?p=237319"},"modified":"2021-01-01T01:20:56","modified_gmt":"2020-12-31T17:20:56","slug":"%e7%94%b1%e4%ba%8e%e5%93%88%e5%b8%8c%e5%86%b2%e7%aa%81%ef%bc%8c%e4%b8%8d%e5%90%8c%e5%80%bc%e7%9a%84%e5%af%b9%e8%b1%a1%e4%b9%9f%e5%8f%af%e8%83%bd%e5%85%b7%e6%9c%89%e7%9b%b8%e5%90%8c%e7%9a%84%e5%93%88","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=237319","title":{"rendered":"\u7531\u4e8e\u54c8\u5e0c\u51b2\u7a81\uff0c\u4e0d\u540c\u503c\u7684\u5bf9\u8c61\u4e5f\u53ef\u80fd\u5177\u6709\u76f8\u540c\u7684\u54c8\u5e0c\u503c"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u7531\u4e8e\u54c8\u5e0c\u51b2\u7a81\uff0c\u4e0d\u540c\u503c\u7684\u5bf9\u8c61\u4e5f\u53ef\u80fd\u5177\u6709\u76f8\u540c\u7684\u54c8\u5e0c\u503c               <\/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\">                        \u7531\u4e8e\u54c8\u5e0c\u51b2\u7a81\uff0c\u4e0d\u540c\u503c\u7684\u5bf9\u8c61\u4e5f\u53ef\u80fd\u5177\u6709\u76f8\u540c\u7684\u54c8\u5e0c\u503c\u3002\u8fd9\u662f\u4e3a\u4ec0\u4e48\u5462?\u4eca\u5929\u756a\u8304\u52a0\u901f\u5c31\u6765\u5206\u6790\u4e00\u4e0b\u3002<\/p>\n<p>\u3000\u3000\u5b57\u7b26\u4e32\u9a7b\u7559<\/p>\n<p>\u3000\u3000 In [1]: a = &#8216;something&#8217;<\/p>\n<p>\u3000\u3000&#8230;: b = &#8216;some&#8217;+&#8217;thing&#8217;<\/p>\n<p>\u3000\u3000&#8230;: id(a)==id(b)<\/p>\n<p>\u3000\u3000 Out[1]: True<\/p>\n<p>\u3000\u3000\u5982\u679c\u4e0a\u9762\u4f8b\u5b50\u8fd4\u56de True\uff0c\u4f46\u662f\u4e0b\u9762\u4f8b\u5b50\u4e3a\u4ec0\u4e48\u662f False:<\/p>\n<p>\u3000\u3000 In [1]: a = &#8216;@zglg.com&#8217;<\/p>\n<p>\u3000\u3000 In [2]: b = &#8216;@zglg&#8217;+&#8217;.com&#8217;<\/p>\n<p>\u3000\u3000 In [3]: id(a)==id(b)<\/p>\n<p>\u3000\u3000 Out[3]: False<\/p>\n<p>\u3000\u3000\u8fd9\u4e0e Cpython \u7f16\u8bd1\u4f18\u5316\u76f8\u5173\uff0c\u884c\u4e3a\u79f0\u4e3a\u5b57\u7b26\u4e32\u9a7b\u7559\uff0c\u4f46\u9a7b\u7559\u7684\u5b57\u7b26\u4e32\u4e2d\u53ea\u5305\u542b\u5b57\u6bcd\uff0c\u6570\u5b57\u6216\u4e0b\u5212\u7ebf\u3002<\/p>\n<p>\u3000\u3000\u76f8\u540c\u503c\u7684\u4e0d\u53ef\u53d8\u5bf9\u8c61<\/p>\n<p>\u3000\u3000 In [5]: d = {}<\/p>\n<p>\u3000\u3000&#8230;: d[1] = &#8216;java&#8217;<\/p>\n<p>\u3000\u3000&#8230;: d[1.0] = &#8216;python&#8217;<\/p>\n<p>\u3000\u3000 In [6]: d<\/p>\n<p>\u3000\u3000 Out[6]: {1: &#8216;python&#8217;}<\/p>\n<p>\u3000\u3000### key=1,value=java \u7684\u952e\u503c\u5bf9\u795e\u5668\u6d88\u5931\u4e86<\/p>\n<p>\u3000\u3000 In [7]: d[1]<\/p>\n<p>\u3000\u3000 Out[7]: &#8216;python&#8217;<\/p>\n<p>\u3000\u3000 In [8]: d[1.0]<\/p>\n<p>\u3000\u3000 Out[8]: &#8216;python&#8217;<\/p>\n<p>\u3000\u3000\u8fd9\u662f\u56e0\u4e3a\u5177\u6709\u76f8\u540c\u503c\u7684\u4e0d\u53ef\u53d8\u5bf9\u8c61\u5728 Python \u4e2d\u59cb\u7ec8\u5177\u6709\u76f8\u540c\u7684\u54c8\u5e0c\u503c<\/p>\n<p>\u3000\u3000\u7531\u4e8e\u5b58\u5728\u54c8\u5e0c\u51b2\u7a81\uff0c\u4e0d\u540c\u503c\u7684\u5bf9\u8c61\u4e5f\u53ef\u80fd\u5177\u6709\u76f8\u540c\u7684\u54c8\u5e0c\u503c\u3002<\/p>\n<p>\u3000\u3000\u5bf9\u8c61\u9500\u6bc1\u987a\u5e8f<\/p>\n<p>\u3000\u3000\u521b\u5efa\u4e00\u4e2a\u7c7b SE:<\/p>\n<p>\u3000\u3000 class SE(object):<\/p>\n<p>\u3000\u3000 def __init__(self):<\/p>\n<p>\u3000\u3000 print(&#8216;init&#8217;)<\/p>\n<p>\u3000\u3000 def __del__(self):<\/p>\n<p>\u3000\u3000 print(&#8216;del&#8217;)<\/p>\n<p>\u3000\u3000\u521b\u5efa\u4e24\u4e2a SE \u5b9e\u4f8b\uff0c\u4f7f\u7528 is \u5224\u65ad\uff1a<\/p>\n<p>\u3000\u3000 In [63]: SE() is SE()<\/p>\n<p>\u3000\u3000 init<\/p>\n<p>\u3000\u3000 init<\/p>\n<p>\u3000\u3000 del<\/p>\n<p>\u3000\u3000 del<\/p>\n<p>\u3000\u3000 Out[63]: False<\/p>\n<p>\u3000\u3000\u521b\u5efa\u4e24\u4e2a SE \u5b9e\u4f8b\uff0c\u4f7f\u7528 id \u5224\u65ad\uff1a<\/p>\n<p>\u3000\u3000 In [64]: id(SE()) == id(SE())<\/p>\n<p>\u3000\u3000 init<\/p>\n<p>\u3000\u3000 del<\/p>\n<p>\u3000\u3000 init<\/p>\n<p>\u3000\u3000 del<\/p>\n<p>\u3000\u3000 Out[64]: True<\/p>\n<p>\u3000\u3000\u8c03\u7528 id \u51fd\u6570, Python \u521b\u5efa\u4e00\u4e2a SE \u7c7b\u7684\u5b9e\u4f8b\uff0c\u5e76\u4f7f\u7528 id \u51fd\u6570\u83b7\u5f97\u5185\u5b58\u5730\u5740\u540e\uff0c\u9500\u6bc1\u5185\u5b58\u4e22\u5f03\u8fd9\u4e2a\u5bf9\u8c61\u3002<\/p>\n<p>\u3000\u3000\u5f53\u8fde\u7eed\u4e24\u6b21\u8fdb\u884c\u6b64\u64cd\u4f5c, Python \u4f1a\u5c06\u76f8\u540c\u7684\u5185\u5b58\u5730\u5740\u5206\u914d\u7ed9\u7b2c\u4e8c\u4e2a\u5bf9\u8c61\uff0c\u6240\u4ee5\u4e24\u4e2a\u5bf9\u8c61\u7684 id \u503c\u662f\u76f8\u540c\u7684.<\/p>\n<p>\u3000\u3000\u4f46\u662f is \u884c\u4e3a\u5374\u4e0e\u4e4b\u4e0d\u540c\uff0c\u901a\u8fc7\u6253\u5370\u987a\u5e8f\u5c31\u53ef\u4ee5\u770b\u5230\u3002<\/p>\n<p>\u3000\u3000\u5145\u5206\u8ba4\u8bc6 for<\/p>\n<p>\u3000\u3000 In [65]: for i in range(5):<\/p>\n<p>\u3000\u3000&#8230;: print(i)<\/p>\n<p>\u3000\u3000&#8230;: i = 10<\/p>\n<p>\u3000\u3000 0<\/p>\n<p>\u3000\u3000 1<\/p>\n<p>\u3000\u3000 2<\/p>\n<p>\u3000\u3000 3<\/p>\n<p>\u3000\u3000 4<\/p>\n<p>\u3000\u3000\u4e3a\u4ec0\u4e48\u4e0d\u662f\u6267\u884c\u4e00\u6b21\u5c31\u9000\u51fa?<\/p>\n<p>\u3000\u3000\u6309\u7167 for \u5728 Python \u4e2d\u7684\u5de5\u4f5c\u65b9\u5f0f, i = 10 \u5e76\u4e0d\u4f1a\u5f71\u54cd\u5faa\u73af\u3002range(5)\u751f\u6210\u7684\u4e0b\u4e00\u4e2a\u5143\u7d20\u5c31\u88ab\u89e3\u5305\uff0c\u5e76\u8d4b\u503c\u7ed9\u76ee\u6807\u5217\u8868\u7684\u53d8\u91cf i.<\/p>\n<p>\u3000\u3000\u8ba4\u8bc6\u6267\u884c\u65f6\u673a<\/p>\n<p>\u3000\u3000 array = [1, 3, 5]<\/p>\n<p>\u3000\u3000 g = (x for x in array if array.count(x) &gt; 0)<\/p>\n<p>\u3000\u3000 g \u4e3a\u751f\u6210\u5668\uff0clist(g)\u540e\u8fd4\u56de[1,3,5]\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u5143\u7d20\u80af\u5b9a\u81f3\u5c11\u90fd\u51fa\u73b0\u4e00\u6b21\u3002\u6240\u4ee5\u8fd9\u4e2a\u7ed3\u679c\u8fd9\u4e0d\u8db3\u4e3a\u5947\u3002\u4f46\u662f\uff0c\u8bf7\u770b\u4e0b\u4f8b\uff1a<\/p>\n<p>\u3000\u3000 array = [1, 3, 5]<\/p>\n<p>\u3000\u3000 g = (x for x in array if array.count(x) &gt; 0)<\/p>\n<p>\u3000\u3000 array = [5, 7, 9]<\/p>\n<p>\u3000\u3000\u8bf7\u95ee,list(g)\u7b49\u4e8e\u591a\u5c11?\u8fd9\u4e0d\u662f\u548c\u4e0a\u9762\u90a3\u4e2a\u4f8b\u5b50\u7ed3\u679c\u4e00\u6837\u5417\uff0c\u7ed3\u679c\u4e5f\u662f[1,3,5]\uff0c\u4f46\u662f\uff1a<\/p>\n<p>\u3000\u3000 In [74]: list(g)<\/p>\n<p>\u3000\u3000 Out[74]: [5]<\/p>\n<p>\u3000\u3000\u8fd9\u6709\u4e9b\u4e0d\u53ef\u601d\u8bae~~ \u539f\u56e0\u5728\u4e8e\uff1a<\/p>\n<p>\u3000\u3000\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u4e2d, in \u5b50\u53e5\u5728\u58f0\u660e\u65f6\u6267\u884c, \u800c\u6761\u4ef6\u5b50\u53e5\u5219\u662f\u5728\u8fd0\u884c\u65f6\u6267\u884c\u3002<\/p>\n<p>\u3000\u3000\u6240\u4ee5\u4ee3\u7801\uff1a<\/p>\n<p>\u3000\u3000 array = [1, 3, 5]<\/p>\n<p>\u3000\u3000 g = (x for x in array if array.count(x) &gt; 0)<\/p>\n<p>\u3000\u3000 array = [5, 7, 9]<\/p>\n<p>\u3000\u3000\u7b49\u4ef7\u4e8e\uff1a<\/p>\n<p>\u3000\u3000 g = (x for x in [1,3,5] if [5,7,9].count(x) &gt; 0)<\/p>\n<p>\u3000\u3000\u770b\u660e\u767d\u4e86\u5417?      <\/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>\u7531\u4e8e\u54c8\u5e0c\u51b2\u7a81\uff0c\u4e0d\u540c\u503c\u7684\u5bf9\u8c61\u4e5f\u53ef\u80fd\u5177&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\/237319"}],"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=237319"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/237319\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=237319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=237319"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=237319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}