{"id":728,"date":"2021-01-25T09:45:27","date_gmt":"2021-01-25T01:45:27","guid":{"rendered":"http:\/\/refusea.com\/?p=728"},"modified":"2021-01-25T10:23:45","modified_gmt":"2021-01-25T02:23:45","slug":"java-%e7%a8%8b%e5%ba%8f%e7%8c%bf%e5%ad%a6-python%ef%bc%9apython-%e7%9a%84-list-%e5%92%8c-tuple","status":"publish","type":"post","link":"https:\/\/refusea.com\/?p=728","title":{"rendered":"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple"},"content":{"rendered":"<h2>\u95ee\u9898<\/h2>\n<p>tuple \u5c31\u662f\u4e0d\u53ef\u53d8\u7684 list\uff0c\u8fd9\u6837\u7684\u7406\u89e3\u5bf9\u5417\uff1f<\/p>\n<h2>\u56de\u7b54<\/h2>\n<p>\u5982\u679c\u4ee5 Java \u7a0b\u5e8f\u733f\u6765\u8bf4\uff0c\u57fa\u672c\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u662f\u5728 python \u7684\u4e16\u754c\uff0c\u5e76\u4e0d\u662f\u8fd9\u4e48\u7b80\u5355\uff0ctuple \u76f8\u5bf9\u4e8e list \u6765\u8bf4\uff0c\u6709 3 \u4e2a\u4e3b\u8981\u7684\u5dee\u5f02<\/p>\n<ul>\n<li>\u4e0d\u53ef\u53d8<\/li>\n<li>\u56fa\u5b9a\u957f\u5ea6<\/li>\n<li>\u5143\u7d20\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u9700\u8981\u4fdd\u6301\u4e00\u81f4<\/li>\n<\/ul>\n<h2>\u4e0d\u53ef\u53d8<\/h2>\n<p>\u4ee5\u4e0b\u7684\u4ee3\u7801\u5c06\u4e00\u4e2a list \u8f6c\u6362\u4e3a tuple<\/p>\n<pre><code class=\"language-python\">>&gt;&gt; x = [1,2,3]\n>&gt;&gt; y = tuple(x)\n>&gt;&gt; y\n(1, 2, 3)<\/code><\/pre>\n<p>\u5c06\u4e00\u4e2a list \u8f6c\u6362\u4e3a tuple\uff0c\u6709\u5f88\u591a\u4f18\u70b9<\/p>\n<ul>\n<li>\u5373\u4f7f\u5b58\u50a8\u76f8\u540c\u6570\u91cf\u7684\u5143\u7d20\uff0ctuple \u5360\u7528\u7684\u5185\u5b58\u8981\u5c11\u4e8e list<\/li>\n<li>tuple \u4e0d\u53ef\u53d8\uff0c\u8fd9\u6837\u5c31\u4e0d\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\uff0c\u4e5f\u53ef\u4ee5\u4f5c\u4e3a dict \u7684 key \u6765\u4f7f\u7528<\/li>\n<\/ul>\n<p>\u4e3a\u4ec0\u4e48\u8981\u8fd9\u6837\u8f6c\u6362\u5462\uff1f\u4e00\u822c\u6765\u8bf4\uff0c\u4e3b\u8981\u662f\u4e3a\u4e86\u6027\u80fd\uff0c\u4e0d\u53ef\u53d8\u7684 tuple \u6027\u80fd\u6bd4 list \u597d\uff0c\u5e76\u4e14\u4e0d\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898<\/p>\n<h2>\u56fa\u5b9a\u957f\u5ea6<\/h2>\n<p>\u8fd9\u4e2a\u7279\u6027\u5f88\u5bb9\u6613\u88ab\u5ffd\u89c6<\/p>\n<p>\u6240\u8c13\u56fa\u5b9a\u957f\u5ea6\uff0c\u610f\u5473\u7740 tuple \u7684\u4f7f\u7528\u8005\u5bf9\u5176\u542b\u6709\u51e0\u4e2a\u5143\u7d20\u662f\u5f88\u6e05\u695a\u7684\uff0c\u5728\u4e0a\u9762\u5c06 list \u8f6c\u4e3a tuple \u7684\u8fc7\u7a0b\u4e2d\uff0c\u5176\u5b9e\u6211\u4eec\u5e76\u4e0d\u77e5\u9053\u8fd4\u56de\u7684 tuple \u7684\u957f\u5ea6<\/p>\n<p>\u6bd4\u8f83\u5178\u578b\u7684\u4f7f\u7528 tuple \u7684\u573a\u666f\u662f\u51fd\u6570\u8fd4\u56de\u591a\u4e2a\u503c\u7684\u60c5\u51b5\uff0c\u5982\u4e0b\u4f8b<\/p>\n<pre><code class=\"language-python\">import datetime\n\ndef today():\n    now = datetime.datetime.now()\n    return now.year, now.month, now.day\n\nif __name__ == &#039;__main__&#039;:\n    print(today())<\/code><\/pre>\n<p>\u8c03\u7528 today() \u65b9\u6cd5\u8fd4\u56de\u5f53\u524d\u7684 \u5e74\u3001\u6708\u3001\u65e5\uff0c\u5982\u4e0b<\/p>\n<pre><code class=\"language-python\">(2021, 1, 25)<\/code><\/pre>\n<p>\u5f88\u660e\u663e\uff0c\u6211\u4eec\u77e5\u9053\u8be5\u65b9\u6cd5\u8981\u8fd4\u56de 3 \u4e2a\u503c<\/p>\n<h2>\u6570\u636e\u7c7b\u578b<\/h2>\n<p>\u901a\u5e38\u6211\u4eec\u4f7f\u7528 list \u65f6\uff0clist \u91cc\u7684\u5143\u7d20\u662f\u76f8\u540c\u7c7b\u578b\u7684\uff1b\u800c\u4f7f\u7528 tuple \u65f6\uff0c\u4e00\u822c\u6ca1\u6709\u8fd9\u6837\u7684\u5171\u8bc6<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5f53\u6211\u4eec\u9700\u8981\u7ed9\u65b9\u6cd5\u4f20\u9012\u4e00\u4e9b\u53c2\u6570\u65f6\uff0c\u5728 Java \u7684\u4e16\u754c\u91cc\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u7528 Map<\/p>\n<p>\u6bd4\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff0c\u5c06\u8bf7\u6c42\u53c2\u6570\u62fc\u63a5\u5230 url \u91cc\u5f97\u5230\u4e00\u4e2a\u5b8c\u6574\u7684 url\uff08\u793a\u4f8b\u4ee3\u7801\uff0c\u672a\u8003\u8651 url encode\uff09<\/p>\n<pre><code class=\"language-java\">public String getFullUrl(String url, Map&lt;String, ?&gt; params) {\n    StringBuilder fullUrl = new StringBuilder(url);\n    for (Map.Entry&lt;String, ?&gt; entry : params.entrySet()) {\n        fullUrl.append(entry.getKey()).append(&#039;=&#039;).append(entry.getValue()).append(&#039;&amp;&#039;);\n    }\n    return fullUrl.toString();\n}<\/code><\/pre>\n<p>\u53c8\u6bd4\u5982 mybatis \u7528 Map \u4f20\u9012\u591a\u4e2a\u53c2\u6570<\/p>\n<p>\u601d\u8003\u4e0b\uff0c\u8fd9\u6837\u7684\u573a\u666f\u771f\u7684\u9700\u8981\u7528 map \u5417\uff1f\u4ece\u4ee3\u7801\u91cc\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u771f\u6b63\u9700\u8981\u7684\u662f\u4e00\u4e2a key-value \u7684\u5217\u8868\uff0c\u5373 <code>params.entrySet()<\/code><\/p>\n<p>\u5982\u679c\u6709 <code>List&lt;KeyValuePair&gt;<\/code> \u8fd9\u6837\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5b8c\u5168\u53ef\u4ee5\u5e94\u5bf9\u8fd9\u6837\u7684\u4f7f\u7528\u573a\u666f\uff0c\u4e14\u8d44\u6e90\u7684\u6d88\u8017\u8981\u5c11\u4e8e Map<\/p>\n<p>\u5728 python \u7684\u4e16\u754c\u91cc\uff0c\u6211\u5efa\u8bae\u7528 tuple \u5217\u8868\uff0c\u5373<\/p>\n<pre><code class=\"language-python\">[(k1, v1), (k2, v2), (k3, v3)...]<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a key \u548c value \u7684\u6570\u636e\u7c7b\u578b\u662f\u53ef\u4ee5\u4e0d\u4e00\u6837\u7684<\/p>\n<p>\u5927\u5bb6\u53ef\u4ee5\u7559\u610f\u4e0b\uff0cpython \u7684\u5f88\u591a\u51fd\u6570\u662f\u65e2\u652f\u6301 dict \u53c2\u6570\uff0c\u4e5f\u652f\u6301 tuple \u5217\u8868\u53c2\u6570\u7684\uff0c\u6bd4\u5982 request \u5e93\uff0c\u770b\u4e0b\u5176\u6700\u6838\u5fc3\u65b9\u6cd5 request \u7684\u6587\u6863\u91cc\u5173\u4e8e\u4ee5\u4e0b\u53c2\u6570\u7684\u8bf4\u660e<\/p>\n<ul>\n<li>params \u2013 (optional) Dictionary, list of tuples or bytes to send in the query string for the Request.<\/li>\n<li>data \u2013 (optional) Dictionary, list of tuples, bytes, or file-like object to send in the body of the Request.<\/li>\n<\/ul>\n<h2>\u7ed3\u8bba<\/h2>\n<p>tuple \u4e0d\u6b62\u662f\u4e0d\u53ef\u53d8\u7684 list \u8fd9\u4e48\u7b80\u5355\uff0c\u8df3\u51fa Java \u7a0b\u5e8f\u733f\u601d\u7ef4\u60ef\u6027\u624d\u80fd\u66f4\u597d\u7684\u7406\u89e3 tuple<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898 tuple \u5c31\u662f\u4e0d\u53ef\u53d8\u7684 list\uff0c\u8fd9\u6837\u7684\u7406\u89e3\u5bf9\u5417\uff1f \u56de\u7b54 \u5982\u679c\u4ee5 Java \u7a0b\u5e8f\u733f\u6765\u8bf4\uff0c\u57fa\u672c\u6ca1\u6709\u95ee\u9898\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-728","post","type-post","status-publish","format-standard","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple - \u62d2\u6d77\u7a7a\u95f4<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/refusea.com\/?p=728\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"refusea.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/refusea.com\/?p=728#article\",\"isPartOf\":{\"@id\":\"https:\/\/refusea.com\/?p=728\"},\"author\":{\"name\":\"refusea.com\",\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\"},\"headline\":\"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple\",\"datePublished\":\"2021-01-25T01:45:27+00:00\",\"dateModified\":\"2021-01-25T02:23:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/refusea.com\/?p=728\"},\"wordCount\":90,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\"},\"articleSection\":[\"python\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/refusea.com\/?p=728#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/refusea.com\/?p=728\",\"url\":\"https:\/\/refusea.com\/?p=728\",\"name\":\"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple - \u62d2\u6d77\u7a7a\u95f4\",\"isPartOf\":{\"@id\":\"https:\/\/refusea.com\/#website\"},\"datePublished\":\"2021-01-25T01:45:27+00:00\",\"dateModified\":\"2021-01-25T02:23:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/refusea.com\/?p=728#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/refusea.com\/?p=728\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/refusea.com\/?p=728#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/refusea.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/refusea.com\/#website\",\"url\":\"https:\/\/refusea.com\/\",\"name\":\"\u62d2\u6d77\u7a7a\u95f4\",\"description\":\"\u62d2\u6d77\u7684\u4e2a\u4eba\u535a\u5ba2\",\"publisher\":{\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/refusea.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df\",\"name\":\"refusea.com\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g\",\"caption\":\"refusea.com\"},\"logo\":{\"@id\":\"https:\/\/refusea.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/refusea.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple - \u62d2\u6d77\u7a7a\u95f4","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/refusea.com\/?p=728","twitter_misc":{"\u4f5c\u8005":"refusea.com","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/refusea.com\/?p=728#article","isPartOf":{"@id":"https:\/\/refusea.com\/?p=728"},"author":{"name":"refusea.com","@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df"},"headline":"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple","datePublished":"2021-01-25T01:45:27+00:00","dateModified":"2021-01-25T02:23:45+00:00","mainEntityOfPage":{"@id":"https:\/\/refusea.com\/?p=728"},"wordCount":90,"commentCount":0,"publisher":{"@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df"},"articleSection":["python"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/refusea.com\/?p=728#respond"]}]},{"@type":"WebPage","@id":"https:\/\/refusea.com\/?p=728","url":"https:\/\/refusea.com\/?p=728","name":"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple - \u62d2\u6d77\u7a7a\u95f4","isPartOf":{"@id":"https:\/\/refusea.com\/#website"},"datePublished":"2021-01-25T01:45:27+00:00","dateModified":"2021-01-25T02:23:45+00:00","breadcrumb":{"@id":"https:\/\/refusea.com\/?p=728#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/refusea.com\/?p=728"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/refusea.com\/?p=728#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/refusea.com\/"},{"@type":"ListItem","position":2,"name":"Java \u7a0b\u5e8f\u733f\u5b66 python\uff1apython \u7684 list \u548c tuple"}]},{"@type":"WebSite","@id":"https:\/\/refusea.com\/#website","url":"https:\/\/refusea.com\/","name":"\u62d2\u6d77\u7a7a\u95f4","description":"\u62d2\u6d77\u7684\u4e2a\u4eba\u535a\u5ba2","publisher":{"@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/refusea.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/refusea.com\/#\/schema\/person\/b5393cc8b15717000d19424552aae0df","name":"refusea.com","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/refusea.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7f7489b4afdbd952db64e7a6704d1258?s=96&d=mm&r=g","caption":"refusea.com"},"logo":{"@id":"https:\/\/refusea.com\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/refusea.com"]}]}},"_links":{"self":[{"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts\/728"}],"collection":[{"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=728"}],"version-history":[{"count":4,"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts\/728\/revisions"}],"predecessor-version":[{"id":732,"href":"https:\/\/refusea.com\/index.php?rest_route=\/wp\/v2\/posts\/728\/revisions\/732"}],"wp:attachment":[{"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/refusea.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}