{"id":137,"date":"2017-01-14T21:39:18","date_gmt":"2017-01-14T12:39:18","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=137"},"modified":"2020-03-21T23:17:35","modified_gmt":"2020-03-21T14:17:35","slug":"list%e5%9e%8b%e3%83%aa%e3%82%b9%e3%83%88-list%e3%81%ae%e6%9b%b4%e6%96%b0%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/137","title":{"rendered":"list(\u30ea\u30b9\u30c8)\u578b\u306e\u66f4\u65b0\u3068\u524a\u9664"},"content":{"rendered":"<p><a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/134\">\u524d\u56de<\/a>\u306e\u7d9a\u304d\u3067\u3059\u3002\u30ea\u30b9\u30c8\u306e\u66f4\u65b0\u7cfb\u306e\u64cd\u4f5c\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<h2>\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u3092\u66f4\u65b0<\/h2>\n<p>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u3001list\u306e\u8981\u7d20\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u304c\u3001\u4ee3\u5165\u3059\u308b\u3053\u3068\u306b\u3088\u308alist\u306e\u8981\u7d20\u3092\u66f4\u65b0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u66f4\u65b0<\/span><\/div>\n\u30ea\u30b9\u30c8\u578b\u5909\u6570[\u30a4\u30f3\u30c7\u30c3\u30af\u30b9] = \u66f4\u65b0\u5024<br \/>\n<\/div>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = [1, 2, 3, 4, 0]\r\nl[0] = 99\r\nprint(l) # [99, 2, 3, 4, 0]\r\n<\/pre>\n<p>\u3053\u306e\u4f8b\u306e\u5834\u5408\u30010\u756a\u76ee\u306e\u8981\u7d20\u304c\u521d\u671f\u5316\u6642\u306b1\u3067\u3057\u305f\u304c\u300199\u306b\u66f4\u65b0\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30ea\u30b9\u30c8\u306b\u8981\u7d20\u3092\u8ffd\u52a0<\/h2>\n<p>\u30ea\u30b9\u30c8\u306e\u6700\u5f8c\u5c3e\u306b\u8981\u7d20\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u306f\u3001append\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3057\u307e\u3059\u3002<br \/>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u8981\u7d20\u306e\u8ffd\u52a0<\/span><\/div>\n\u30ea\u30b9\u30c8\u578b\u5909\u6570.append(\u8ffd\u52a0\u3057\u305f\u3044\u5909\u6570)<br \/>\n<\/div>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = [1, 2, 3]\r\nl.append(4)\r\nprint(l) # [1, 2, 3, 4]\r\n<\/pre>\n<p>\u4e00\u756a\u6700\u5f8c\u306b4\u304c\u8ffd\u52a0\u3055\u308c\u305f\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30ea\u30b9\u30c8\u306b\u8981\u7d20\u3092\u633f\u5165<\/h2>\n<p>\u9014\u4e2d\u306b\u8981\u7d20\u3092\u8ffd\u52a0\u3059\u308b\u5834\u5408\u3001insert\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3057\u307e\u3059\u3002<br \/>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u7279\u5b9a\u306e\u4f4d\u7f6e\u306b\u8981\u7d20\u3092\u8ffd\u52a0<\/span><\/div>\nlist\u578b\u5909\u6570.insert(\u633f\u5165\u3059\u308b\u4f4d\u7f6e\u3092\u793a\u3059\u30a4\u30f3\u30c7\u30c3\u30af\u30b9, \u633f\u5165\u3059\u308b\u5909\u6570)<br \/>\n<\/div>\n<p>\u30b5\u30f3\u30d7\u30eb\u3067\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# 0\u756a\u76ee\u306b\u633f\u5165\u3059\u308b\r\nl = ['a', 'b', 'c']\r\nl.insert(0, 'x')\r\nprint(l) # ['x', 'a', 'b', 'c']\r\n\r\n# 2\u756a\u76ee\u306b\u633f\u5165\u3059\u308b\r\nl.insert(2, 'y')\r\nprint(l) # ['x', 'a', 'y', 'b', 'c']\r\n\r\n# \u6700\u5f8c\u5c3e\u306b\u633f\u5165\u3059\u308b\r\nl.insert(-1, 'z')\r\nprint(l) # ['x', 'a', 'y', 'b', 'z', 'c']\r\n\r\n<\/pre>\n<p>\u6307\u5b9a\u3057\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u4f4d\u7f6e\u306b\u633f\u5165\u3055\u308c\u305f\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u3092\u524a\u9664<\/h2>\n<p>\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u524a\u9664\u306b\u306f\u3044\u304f\u3064\u304b\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002\u9806\u756a\u306b\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u6307\u5b9a\u3057\u305f\u8981\u7d20\u3092\u524a\u9664<\/h3>\n<p>\u6307\u5b9a\u3057\u305f\u8981\u7d20\u3092\u524a\u9664\u3059\u308b\u5834\u5408\u306f\u3001remove\u95a2\u6570\u3092\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = ['a', 'b', 'c', 'd', 'c']\r\n\r\n# a\u3092\u524a\u9664\u3059\u308b\r\nl.remove('a')\r\nprint(l) # ['b', 'c', 'd', 'c']\r\n\r\n# \u91cd\u8907\u3057\u305f\u5024\u3092\u524a\u9664\u3059\u308b\u3068\u3001\u5148\u982d\u5074\u306e\u3082\u306e\u304c\u524a\u9664\u3055\u308c\u308b\r\nl.remove('c')\r\nprint(l) # ['b', 'd', 'c']\r\n\r\n# \u5b58\u5728\u3057\u306a\u3044\u5024\u3092\u6307\u5b9a\u3059\u308b\u3068ValueError\u304c\u767a\u751f\r\nl.remove('e') # ValueError: list.remove(x): x not in list\r\n\r\n<\/pre>\n<p>\u6307\u5b9a\u3057\u305f\u5024\u304c\u524a\u9664\u3055\u308c\u307e\u3059\u304c\u3001\u540c\u3058\u5024\u304c\u30ea\u30b9\u30c8\u306b\u633f\u5165\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u5148\u982d\u5074\u306e\u5024\u304c\u524a\u9664\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30ea\u30b9\u30c8\u306b\u5b58\u5728\u3057\u306a\u3044\u5024\u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u3001ValueError\u304c\u767a\u751f\u3059\u308b\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u6307\u5b9a\u3057\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u524a\u9664<\/h3>\n<p>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u524a\u9664\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002del\u6587\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3068pop\u30e1\u30bd\u30c3\u30c9\u3092\u5229\u7528\u3059\u308b2\u3064\u306e\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h4>del\u6587<\/h4>\n<p>del\u306e\u69cb\u6587\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u524a\u9664<\/span><\/div>\ndel list\u578b\u5909\u6570[\u524a\u9664\u5bfe\u8c61\u30a4\u30f3\u30c7\u30c3\u30af\u30b9]\n<\/div>\n<p>\u3055\u3063\u305d\u304f\u4f7f\u3044\u65b9\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f(0\u756a\u76ee\u304b\u3089\u6570\u3048\u3066)2\u756a\u76ee\u306e\u8981\u7d20\u304c\u524a\u9664\u3055\u308c\u305f\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = ['a', 'b', 'c', 'd']\r\n\r\ndel l[2] # \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c2\u306e\u8981\u7d20\u3092\u524a\u9664\r\nprint(l) # ['a', 'b', 'd']\r\n<\/pre>\n<p>\u5148\u982d\u3001\u672b\u5c3e\u3092\u524a\u9664\u3059\u308b\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u305d\u308c\u305e\u308c0\u3001-1\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = ['a', 'b', 'c', 'd']\r\n\r\ndel l[0] # \u6700\u521d\u306e\u8981\u7d20\u3092\u524a\u9664\r\nprint(l) # ['b', 'c', 'd']\r\n\r\n\r\ndel l[-1] # \u6700\u5f8c\u306e\u8981\u7d20\u3092\u524a\u9664\r\nprint(l) # ['b', 'c']\r\n\r\n<\/pre>\n<p>\u3082\u3061\u308d\u3093\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u6307\u5b9a\u306b\u30b9\u30e9\u30a4\u30b9\u69cb\u6587\u3092\u4f7f\u3046\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = ['a', 'b', 'c', 'd']\r\n\r\ndel l[0:2] # 0\u756a\u76ee\u304b\u30892\u756a\u76ee\u524d\u307e\u3067\u524a\u9664\r\nprint(l) # ['c', 'd']\r\n<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001(0\u304b\u3089\u6570\u3048\u3066)0\u756a\u76ee\u304b\u30892\u756a\u76ee\u306e\u624b\u524d\u307e\u3067\u524a\u9664\u3055\u308c\u307e\u3059\u3002(0\u304b\u3089\u6570\u3048\u3066)2\u756a\u76ee\u81ea\u8eab\u306f\u524a\u9664\u3055\u308c\u306a\u3044\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h4>pop\u30e1\u30bd\u30c3\u30c9<\/h4>\n<p>\u30ea\u30b9\u30c8\u306b\u306fpop\u30e1\u30bd\u30c3\u30c9\u3068\u3044\u3046\u6307\u5b9a\u3055\u308c\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u8981\u7d20\u3092\u524a\u9664\u3057\u3001\u305d\u306e\u8981\u7d20\u3092\u623b\u308a\u5024\u3068\u3057\u3066\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3053\u308c\u3092\u524a\u9664\u3068\u3057\u3066\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = ['a', 'b', 'c', 'd']\r\n\r\nx = l.pop(2) # 2\u756a\u76ee\u306e\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3057\u3066\u524a\u9664\u3059\u308b\r\nprint(x) # 'c'\r\nprint(l) # ['a', 'b', 'd']\r\n<\/pre>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001pop\u3057\u305f\u5024\u304cx\u306b\u683c\u7d0d\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u5f15\u6570\u306b\u4f55\u3082\u6307\u5b9a\u3057\u306a\u3044\u5834\u5408\u306f\u672b\u5c3e\u306e\u8981\u7d20\u304c\u524a\u9664\u3055\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u56de\u306e\u7d9a\u304d\u3067\u3059\u3002\u30ea\u30b9\u30c8\u306e\u66f4\u65b0\u7cfb\u306e\u64cd\u4f5c\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 \u30ea\u30b9\u30c8\u306e\u8981\u7d20\u3092\u66f4\u65b0 \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u3001list\u306e\u8981\u7d20\u3092\u53c2\u7167\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u304c\u3001\u4ee3\u5165\u3059\u308b\u3053\u3068\u306b\u3088\u308alist\u306e\u8981\u7d20\u3092\u66f4\u65b0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 \u3053\u306e\u4f8b\u306e\u5834\u5408\u3001...<\/p>\n","protected":false},"author":1,"featured_media":3396,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[214,48],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/137"}],"collection":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":19,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/137\/revisions"}],"predecessor-version":[{"id":3399,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/137\/revisions\/3399"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3396"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}