{"id":451,"date":"2017-12-19T15:56:13","date_gmt":"2017-12-19T07:56:13","guid":{"rendered":"http:\/\/luchanglong.com.cn\/?p=451"},"modified":"2017-12-19T15:58:34","modified_gmt":"2017-12-19T07:58:34","slug":"python-%e6%a0%87%e5%87%86%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/blog.la998.com\/?p=451","title":{"rendered":"python \u6807\u51c6\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<p>Python\u6709\u4e94\u4e2a\u6807\u51c6\u7684\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>Numbers\uff08\u6570\u5b57\uff09<\/li>\n<li>String\uff08\u5b57\u7b26\u4e32\uff09<\/li>\n<li>List\uff08\u5217\u8868\uff09<\/li>\n<li>Tuple\uff08\u5143\u7ec4\uff09<\/li>\n<li>Dictionary\uff08\u5b57\u5178\uff09<\/li>\n<\/ul>\n<p><strong>List<\/strong><\/p>\n<p>\u5217\u8868\u662f Python \u4e2d\u4f7f\u7528\u6700\u9891\u7e41\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u5217\u8868\u53ef\u4ee5\u5b8c\u6210\u5927\u591a\u6570\u96c6\u5408\u7c7b\u7684\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\u3002\u5b83\u652f\u6301\u5b57\u7b26\uff0c\u6570\u5b57\uff0c\u5b57\u7b26\u4e32\u751a\u81f3\u53ef\u4ee5\u5305\u542b\u5217\u8868\uff08\u5373\u5d4c\u5957\uff09\u3002<\/p>\n<p>\u5217\u8868\u7528\u00a0<span class=\"marked\">[ ]<\/span>\u00a0\u6807\u8bc6\uff0c\u662f python \u6700\u901a\u7528\u7684\u590d\u5408\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<pre class=\"lang:default decode:true\"> l = ['A', 'b', 'C']<\/pre>\n<p>tuple<\/p>\n<p>\u5143\u7ec4\u662f\u53e6\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\uff0c\u7c7b\u4f3c\u4e8eList\uff08\u5217\u8868\uff09\u3002<\/p>\n<p>\u5143\u7ec4\u7528&#8221;()&#8221;\u6807\u8bc6\u3002\u5185\u90e8\u5143\u7d20\u7528\u9017\u53f7\u9694\u5f00\u3002\u4f46\u662f\u5143\u7ec4\u4e0d\u80fd\u4e8c\u6b21\u8d4b\u503c\uff0c\u76f8\u5f53\u4e8e\u53ea\u8bfb\u5217\u8868\u3002<\/p>\n<pre class=\"lang:default decode:true \">t = ('C', 'D', 'A')<\/pre>\n<p>&nbsp;<\/p>\n<p>dict<\/p>\n<p>\u5b57\u5178(dictionary)\u662f\u9664\u5217\u8868\u4ee5\u5916python\u4e4b\u4e2d\u6700\u7075\u6d3b\u7684\u5185\u7f6e\u6570\u636e\u7ed3\u6784\u7c7b\u578b\u3002\u5217\u8868\u662f\u6709\u5e8f\u7684\u5bf9\u8c61\u96c6\u5408\uff0c\u5b57\u5178\u662f\u65e0\u5e8f\u7684\u5bf9\u8c61\u96c6\u5408\u3002<\/p>\n<p>\u4e24\u8005\u4e4b\u95f4\u7684\u533a\u522b\u5728\u4e8e\uff1a\u5b57\u5178\u5f53\u4e2d\u7684\u5143\u7d20\u662f\u901a\u8fc7\u952e\u6765\u5b58\u53d6\u7684\uff0c\u800c\u4e0d\u662f\u901a\u8fc7\u504f\u79fb\u5b58\u53d6\u3002<\/p>\n<p>\u5b57\u5178\u7528&#8221;{ }&#8221;\u6807\u8bc6\u3002\u5b57\u5178\u7531\u7d22\u5f15(key)\u548c\u5b83\u5bf9\u5e94\u7684\u503cvalue\u7ec4\u6210\u3002<\/p>\n<pre class=\"lang:default decode:true \">d = {'lisa': 90, 'hanmei': 70, 'harry': 85}<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>set<\/strong><\/p>\n<p><b>set()<\/b>\u00a0\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u65e0\u5e8f\u4e0d\u91cd\u590d\u5143\u7d20\u96c6\uff0c\u53ef\u8fdb\u884c\u5173\u7cfb\u6d4b\u8bd5\uff0c\u5220\u9664\u91cd\u590d\u6570\u636e\uff0c\u8fd8\u53ef\u4ee5\u8ba1\u7b97\u4ea4\u96c6\u3001\u5dee\u96c6\u3001\u5e76\u96c6\u7b49\u3002<\/p>\n<pre class=\"lang:default decode:true \">&gt;&gt;&gt;x = set('runoob') \r\n&gt;&gt;&gt; y = set('google') \r\n&gt;&gt;&gt; x, y (set(['b', 'r', 'u', 'o', 'n']), set(['e', 'o', 'g', 'l'])) # \u91cd\u590d\u7684\u88ab\u5220\u9664 \r\n&gt;&gt;&gt; x &amp; y # \u4ea4\u96c6 set(['o']) \r\n&gt;&gt;&gt; x | y # \u5e76\u96c6 set(['b', 'e', 'g', 'l', 'o', 'n', 'r', 'u']) \r\n&gt;&gt;&gt; x - y # \u5dee\u96c6 set(['r', 'b', 'u', 'n']) \r\n&gt;&gt;&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u6709\u4e94\u4e2a\u6807\u51c6\u7684\u6570\u636e\u7c7b\u578b\uff1a Numbers\uff08\u6570\u5b57\uff09 String\uff08\u5b57\u7b26\u4e32\uff09 List\uff08\u5217\u8868\uff09 Tupl &hellip; <a href=\"https:\/\/blog.la998.com\/?p=451\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">python \u6807\u51c6\u6570\u636e\u7c7b\u578b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-451","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=451"}],"version-history":[{"count":5,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/451\/revisions"}],"predecessor-version":[{"id":456,"href":"https:\/\/blog.la998.com\/index.php?rest_route=\/wp\/v2\/posts\/451\/revisions\/456"}],"wp:attachment":[{"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.la998.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}