{"id":134,"date":"2017-01-13T23:38:19","date_gmt":"2017-01-13T14:38:19","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=134"},"modified":"2020-03-21T23:16:42","modified_gmt":"2020-03-21T14:16:42","slug":"list%e5%9e%8b%e3%83%aa%e3%82%b9%e3%83%88-%e3%81%9d%e3%81%ae1","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/134","title":{"rendered":"list(\u30ea\u30b9\u30c8)\u578b\u306e\u57fa\u672c\u3068\u521d\u671f\u5316"},"content":{"rendered":"<p>\u305d\u308c\u3067\u306f\u3053\u3053\u304b\u3089\u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u3072\u3068\u3064\u3001\u30ea\u30b9\u30c8\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3092\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>list\u3068\u306f<\/h2>\n<p><a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/126\">\u524d\u56de<\/a>\u306e\u5192\u982d\u3067\u8efd\u304f\u8aac\u660e\u3057\u307e\u3057\u305f\u304c\u3001list\u578b\u3068\u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u4e00\u7a2e\u3067\u9806\u5e8f\u4ed8\u3051\u3089\u308c\u305f\u8907\u6570\u306e\u5024\u3092\u3072\u3068\u307e\u3068\u307e\u308a\u306e\u5909\u6570\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001for\u6587\u3068\u3044\u3063\u305f\u5236\u5fa1\u6587\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u683c\u7d0d\u3057\u305f\u8907\u6570\u306e\u5024\u3092\u9806\u756a\u306b\u51e6\u7406\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002\u306a\u304a\u3001\u4ee5\u964dlist\u578b\u306e\u5909\u6570\u306e\u3053\u3068\u3092\u5358\u306b\u30ea\u30b9\u30c8\u3068\u8a18\u8ff0\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30ea\u30b9\u30c8\u306f\u751f\u6210\u5f8c\u306b\u5f8c\u304b\u3089\u8981\u7d20\u306e\u5024\u3092\u5909\u3048\u305f\u308a\u3001\u5024\u3092\u633f\u5165\u3057\u305f\u308a\u3001\u5024\u3092\u30bd\u30fc\u30c8\u3057\u305f\u308a\u3068\u3044\u3063\u305f\u69d8\u3005\u306a\u6a5f\u80fd\u304c\u4e88\u3081\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u305f\u3081\u3001\u899a\u3048\u308b\u3053\u3068\u304c\u591a\u3044\u53cd\u9762\u3001\u4f7f\u3044\u3053\u306a\u305b\u308b\u3088\u3046\u306b\u306a\u308b\u3068\u69d8\u3005\u306a\u5834\u9762\u3067\u6d3b\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>list\u306e\u521d\u671f\u5316<\/h2>\n<h3>[]\u3092\u4f7f\u7528\u3057\u305f\u521d\u671f\u5316<\/h3>\n<p>\u3055\u3063\u305d\u304f\u5b9f\u969b\u306blist\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u307e\u305a\u306flist\u578b\u306e\u5909\u6570\u3092\u521d\u671f\u5316\u3001\u751f\u6210\u3057\u307e\u3059\u3002list\u578b\u306e\u5909\u6570\u3092\u751f\u6210\u3059\u308b\u5834\u5408\u306f\u3001\u5927\u30ab\u30c3\u30b3\u306e\u4e2d\u306b\u3001\u30ab\u30f3\u30de\u533a\u5207\u308a\u3067\u5024\u3092\u5217\u6319\u3057\u3066\u521d\u671f\u5024\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<div class=\"c_box intitle yellow_box\"><div class=\"box_title\"><span>\u521d\u671f\u5316<\/span><\/div>\n\u5909\u6570 = [\u8981\u7d201, \u8981\u7d202, , ,]\n<\/div>\n<p>\u5927\u30ab\u30c3\u30b3\u306e\u4e2d\u306b\u4f55\u3082\u66f8\u304b\u306a\u3044\u5834\u5408\u306f\u3001\u7a7a\u306e\u30ea\u30b9\u30c8\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n# \u6570\u5024\u306e\u30ea\u30b9\u30c8\r\nl1 = [1, 3, 5, 7, 9]\r\n\r\n# \u6587\u5b57\u5217\u306e\u30ea\u30b9\u30c8\u3002\u91cd\u8907\u3057\u3066\u3082OK\r\nl2 = ['pen', 'pineapple', 'apple', 'pen']\r\n\r\n# \u578b\u306e\u7570\u306a\u308b\u5909\u6570\u3082\u5165\u308c\u3089\u308c\u308b\r\nl3 = [1, 'pen', l1, l2] \r\n\r\n# \u7a7a\u306e\u30ea\u30b9\u30c8\r\nl4 = []\r\n<\/pre>\n<p>l1\u306f\u6570\u5024\u306e\u30ea\u30b9\u30c8\u3067\u3059\u3002l2\u306f\u6587\u5b57\u5217\u306e\u30ea\u30b9\u30c8\u3067\u3059\u3002\u91cd\u8907\u304c\u3042\u308b\u5024\u3082\u633f\u5165\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u305d\u3057\u3066\u3001l3\u3067\u306f\u3001\u6570\u5024\u3001\u6587\u5b57\u306b\u52a0\u3048\u3001\u30ea\u30b9\u30c8\u578b\u30aa\u30d6\u30b8\u30a7\u30af\u3082\u633f\u5165\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u3046\u3001Python\u306e\u30ea\u30b9\u30c8\u306b\u306f\u4f55\u3067\u3082\u633f\u5165\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u6700\u5f8c\u306el4\u3067\u306f\u7a7a\u306e\u30ea\u30b9\u30c8\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>list\u95a2\u6570\u306b\u3088\u308b\u521d\u671f\u5316<\/h3>\n<p>\u307e\u305f\u3001\u521d\u671f\u5316\u3067\u3082\u3046\u4e00\u3064\u91cd\u8981\u306a\u306e\u304clist\u95a2\u6570\u3068\u547c\u3070\u308c\u308b\u7d44\u307f\u8fbc\u307f\u306e\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002\u5f15\u6570\u306b\u30b7\u30fc\u30b1\u30f3\u30b9\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001\u305d\u306e\u8981\u7d20\u3068\u540c\u3058\u30ea\u30b9\u30c8\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002\u30ea\u30b9\u30c8\u3092\u30b3\u30d4\u30fc\u3059\u308b\u969b\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30f3\u30d7\u30eb\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl1 = [1, 2, 3]\r\nl2 = list(l1)\r\n\r\n<\/pre>\n<p>\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u30ea\u30b9\u30c8l1\u3068\u540c\u3058\u5185\u5bb9\u306e\u30ea\u30b9\u30c8l2\u304c\u751f\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u88dc\u8db3<\/h3>\n<p>\u307e\u305f\u3001list\u306e\u521d\u671f\u5316\u306b\u306f\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18\u3068\u547c\u3070\u308c\u308b\u975e\u5e38\u306b\u5f37\u529b\u306a\u8a18\u6cd5\u304cPython\u306b\u306f\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u5236\u5fa1\u6587\u306efor\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3057\u305f\u5f8c\u8aac\u660e\u3057\u307e\u3059\u3002<a href=\"http:\/\/www.python.ambitious-engineer.com\/archives\/154\">\u30ea\u30b9\u30c8\u5185\u5305\u8868\u8a18<\/a><\/p>\n<h2>\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3059\u308b<\/h2>\n<h3>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u6307\u5b9a<\/h3>\n<p>\u6b21\u306b\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u8b58\u5225\u5b50\u306e\u5f8c\u306b\u5927\u30ab\u30c3\u30b3\u3067\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u304c\u6700\u3082\u7c21\u5358\u3067\u3059\u3002\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\nl = [1, 2, 3, 4, 5]\r\n\r\nprint(l[0]) # 1\r\nprint(l[1]) # 2\r\nprint(l[4]) # 5\r\nprint(l[5]) # IndexError: list index out of range\r\n\r\n<\/pre>\n<p>0\u3092\u6307\u5b9a\u3059\u308b\u3068\u30010\u756a\u76ee\u306e\u8981\u7d20\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001<strong>\u30ea\u30b9\u30c8\u306e\u7bc4\u56f2\u3092\u8d85\u3048\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3059\u308b\u3068\u3001IndexError\u304c\u767a\u751f<\/strong>\u3057\u307e\u3059\u3002<\/p>\n<h3>list\u306e\u6700\u5f8c\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3059\u308b<\/h3>\n<p>Python\u306e\u30ea\u30b9\u30c8\u306flist\u306e\u6700\u5f8c\u306e\u8981\u7d20\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f-1\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u3055\u3089\u306b\u3001\u30de\u30a4\u30ca\u30b9\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3067\u672b\u5c3e\u304b\u3089\u6307\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = [1, 2, 3, 4, 5]\r\n\r\nprint(l[-1]) # 5\r\nprint(l[-4]) # 2\r\nprint(l[-5]) # 1\r\nprint(l[-6]) # IndexError: list index out of range\r\n<\/pre>\n<h3>\u30b9\u30e9\u30a4\u30b9\u69cb\u6587<\/h3>\n<p>\u30de\u30a4\u30ca\u30b9\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u52a0\u3048\u3001Python\u306e\u30ea\u30b9\u30c8\u3067\u91cd\u8981\u306a\u69cb\u6587\u304c\u30b9\u30e9\u30a4\u30b9\u69cb\u6587\u3067\u3059\u3002\u30ea\u30b9\u30c8\u306b\u5bfe\u3057\u7bc4\u56f2\u3092\u6307\u5b9a\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30e9\u30a4\u30b9\u69cb\u6587\u306f\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3068\u7d42\u4e86\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u30b3\u30ed\u30f3\u3067\u3064\u306a\u3052\u3066\u6307\u5b9a\u3057\u307e\u3059\u3002\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u7701\u7565\u3059\u308b\u3068\u3001\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f0\u306b\u306a\u308a\u307e\u3059\u3002\u7d42\u4e86\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u7701\u7565\u3059\u308b\u3068\u3001\u7d42\u4e86\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306f-1\uff08\u6700\u5f8c\u5c3e\uff09\u306b\u306a\u308a\u307e\u3059\u3002<strong>\u7d42\u4e86\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3067\u6307\u5b9a\u3057\u305f\u5024\u306f\u7d50\u679c\u306b\u542b\u307e\u308c\u306a\u3044<\/strong>\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001<strong>\u7bc4\u56f2\u3092\u8d85\u3048\u305f\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u3082\u3001IndexError\u306f\u767a\u751f\u3057\u307e\u305b\u3093\u3002<\/strong><\/p>\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# \u30ea\u30b9\u30c8\u306e\u521d\u671f\u5316\r\nl = ['a', 'b', 'c', 'd', 'e']\r\n\r\n# 0\u756a\u76ee\u304b\u30890\u756a\u76ee\uff081\u756a\u76ee\u306f\u53d6\u5f97\u3055\u308c\u306a\u3044\uff09\r\nprint(l[0:1]) # ['a']\r\n\r\n# 0\u756a\u76ee\u304b\u30891\u756a\u76ee\uff082\u756a\u76ee\u306f\u53d6\u5f97\u3055\u308c\u306a\u3044\uff09\r\nprint(l[0:2]) # ['a', 'b']\r\n\r\n# 1\u756a\u76ee\u304b\u30893\u756a\u76ee\r\nprint(l[1:4]) # ['b', 'c', 'd']\r\n\r\n# 0\u756a\u76ee\u304b\u3089\u6700\u5f8c\u306e\u4e00\u3064\u624b\u524d\u307e\u3067\r\nprint(l[0:-1]) # ['a', 'b', 'c', 'd']\r\n\r\n# 0\u756a\u76ee\u304b\u3089\u6700\u5f8c\u307e\u3067\r\nprint(l[0:]) # ['a', 'b', 'c', 'd', 'e']\r\n\r\n# 0\u756a\u76ee\u304b\u308998\u756a\u76ee\u307e\u3067\uff08\u30a8\u30e9\u30fc\u306f\u767a\u751f\u3057\u306a\u3044\uff09\r\nprint(l[:99]) # ['a', 'b', 'c', 'd', 'e']\r\n\r\n<\/pre>\n<p>\u6700\u521d\u306f\u5c11\u3005\u96e3\u3057\u304f\u611f\u3058\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u306a\u308c\u308b\u3068\u975e\u5e38\u306b\u4fbf\u5229\u306a\u8a18\u6cd5\u3067\u3059\u3002<\/p>\n<h2>list\u306e\u8981\u7d20\u6570\u3092\u78ba\u8a8d\u3059\u308b<\/h2>\n<p>\u30ea\u30b9\u30c8\u306e\u8981\u7d20\u6570\u306flen\u95a2\u6570\u3092\u5229\u7528\u3057\u307e\u3059\u3002\uff08\u5b9f\u306flen\u95a2\u6570\u306f\u30ea\u30b9\u30c8\u306e\u307f\u306a\u3089\u305a\u30b7\u30fc\u30b1\u30f3\u30b9\u578b\u5168\u822c\u3067\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\uff09<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nl = [1, 2, 3, 4, 0]\r\n\r\nprint(len(l)) # 5\r\nprint(l[len(l) - 1]) # 0\r\n<\/pre>\n<p>len\u3067\u8981\u7d20\u6570\u304c\u53d6\u5f97\u51fa\u6765\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u307e\u305f\u3001len\u3067\u53d6\u5f97\u3057\u305f\u5024 - 1\u3067\u30ea\u30b9\u30c8\u306e\u6700\u5f8c\u5c3e\u304c\u53d6\u5f97\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u3082\u78ba\u8a8d\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u305d\u308c\u3067\u306f\u3053\u3053\u304b\u3089\u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u3072\u3068\u3064\u3001\u30ea\u30b9\u30c8\u306b\u3064\u3044\u3066\u5b66\u7fd2\u3092\u3057\u307e\u3057\u3087\u3046\u3002 list\u3068\u306f \u524d\u56de\u306e\u5192\u982d\u3067\u8efd\u304f\u8aac\u660e\u3057\u307e\u3057\u305f\u304c\u3001list\u578b\u3068\u306f\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u4e00\u7a2e\u3067\u9806\u5e8f\u4ed8\u3051\u3089\u308c\u305f\u8907\u6570\u306e\u5024\u3092\u3072\u3068\u307e\u3068\u307e\u308a\u306e\u5909\u6570\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e...<\/p>\n","protected":false},"author":1,"featured_media":3393,"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\/134"}],"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=134"}],"version-history":[{"count":17,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/134\/revisions"}],"predecessor-version":[{"id":1946,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/134\/revisions\/1946"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3393"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=134"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=134"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=134"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}