{"id":2432,"date":"2025-08-21T20:33:28","date_gmt":"2025-08-21T11:03:28","guid":{"rendered":"https:\/\/softasia.jp\/blog\/?p=2432"},"modified":"2025-10-29T19:49:42","modified_gmt":"2025-10-29T10:19:42","slug":"python-%e5%85%a5%e9%96%80%ef%bc%81-enumerate%e3%81%a7%e8%a6%81%e7%b4%a0%ef%bc%86%e3%82%a4%e3%83%b3%e3%83%87%e3%83%83%e3%82%af%e3%82%b9%e3%82%92%e5%90%8c%e6%99%82%e5%8f%96%e5%be%97%ef%bc%81%e5%88%9d","status":"publish","type":"post","link":"https:\/\/softasia.jp\/blog\/offshore\/2432\/","title":{"rendered":"Python \u5165\u9580\uff01 enumerate\u3067\u8981\u7d20\uff06\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u540c\u6642\u53d6\u5f97\uff01\u521d\u5fc3\u8005\u304b\u3089\u5b9f\u52d9\u307e\u3067\u5b8c\u5168\u89e3\u8aac"},"content":{"rendered":"<p><span style=\"font-weight: 400;\"><img loading=\"lazy\" class=\"size-medium wp-image-2460 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-9-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-9-300x169.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-9-1024x576.png 1024w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-9-768x432.png 768w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-9-1536x864.png 1536w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-9.png 2048w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Python\u3067\u30ea\u30b9\u30c8\u3084\u30bf\u30d7\u30eb\u306a\u3069\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u6271\u3046\u969b\u3001\u300c<span style=\"text-decoration: underline;\"><strong>\u8981\u7d20<\/strong><\/span>\u300d\u3068\u300c<span style=\"text-decoration: underline;\"><strong>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7<\/strong><\/span>\u300d\u3092\u540c\u6642\u306b\u53d6\u5f97\u3057\u305f\u3044\u5834\u9762\u306f\u591a\u3005\u3042\u308a\u307e\u3059\u3002\u305d\u3093\u306a\u3068\u304d\u306b\u4fbf\u5229\u306a\u306e\u304c\u3001<span style=\"color: #ff0000;\"><strong>Python\u306e\u7d44\u307f\u8fbc\u307f\u95a2\u6570 enumerate()<\/strong> <\/span>\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Python\u521d\u5fc3\u8005\u5411\u3051\u306b enumerate() \u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u304b\u3089\u3001for\u30eb\u30fc\u30d7\u3068\u306e\u7d44\u307f\u5408\u308f\u305b\u65b9\u3001\u5fdc\u7528\u4f8b\u3001\u6ce8\u610f\u70b9\u307e\u3067\u3092\u308f\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3057\u307e\u3059\u3002Python\u5b66\u7fd2\u8005\u3084\u696d\u52d9\u3067Python\u3092\u4f7f\u3044\u59cb\u3081\u305f\u65b9\u306b\u3068\u3063\u3066\u3001\u5fc5\u305a\u5f79\u7acb\u3064\u5185\u5bb9\u3068\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#Pythonfor\"><span class=\"toc_number toc_depth_1\">1<\/span> Python\u306efor\u30eb\u30fc\u30d7\u306e\u57fa\u672c<\/a><ul><li><a href=\"#rangelen\"><span class=\"toc_number toc_depth_2\">1.1<\/span> \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u2460\uff1arange()\u3068len()<\/a><\/li><li><a href=\"#enumerate\"><span class=\"toc_number toc_depth_2\">1.2<\/span> \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3068\u8981\u7d20\u3092\u540c\u6642\u306b\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u2461\uff1aenumerate()<\/a><\/li><\/ul><\/li><li><a href=\"#enumerate-2\"><span class=\"toc_number toc_depth_1\">2<\/span> enumerate() \u306e\u4ed5\u7d44\u307f<\/a><ul><li><a href=\"#start\"><span class=\"toc_number toc_depth_2\">2.1<\/span> start\u5f15\u6570\u3067\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/a><\/li><\/ul><\/li><li><a href=\"#enumerate-3\"><span class=\"toc_number toc_depth_1\">3<\/span> \u5b9f\u52d9\u3067\u5f79\u7acb\u3064enumerate\u306e\u6d3b\u7528\u4f8b<\/a><ul><li><a href=\"#i\"><span class=\"toc_number toc_depth_2\">3.1<\/span> \u30ed\u30b0\u51fa\u529b\u306b\u884c\u756a\u53f7\u3092\u4ed8\u3051\u308b<\/a><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_2\">3.2<\/span> \u30e6\u30fc\u30b6\u30fc\u5165\u529b\u306e\u691c\u8a3c<\/a><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_2\">3.3<\/span> \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u884c\u756a\u53f7\u3092\u4ed8\u4e0e\u3057\u3066\u767b\u9332<\/a><\/li><li><a href=\"#i-4\"><span class=\"toc_number toc_depth_2\">3.4<\/span> \u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u8fbc\u307f\u6642\u306e\u884c\u756a\u53f7\u7ba1\u7406<\/a><\/li><li><a href=\"#enumerate-4\"><span class=\"toc_number toc_depth_2\">3.5<\/span> \u30cd\u30b9\u30c8\u3057\u305f\u30eb\u30fc\u30d7\u3067\u306eenumerate<\/a><\/li><\/ul><\/li><li><a href=\"#i-5\"><span class=\"toc_number toc_depth_1\">4<\/span> \u3088\u304f\u3042\u308b\u30df\u30b9\u3068\u6ce8\u610f\u70b9<\/a><ul><li><a href=\"#too_many_values_to_unpack\"><span class=\"toc_number toc_depth_2\">4.1<\/span> too many values to unpack \u30a8\u30e9\u30fc<\/a><\/li><li><a href=\"#TypeError_8216int8217_object_is_not_iterable\"><span class=\"toc_number toc_depth_2\">4.2<\/span> TypeError: &#8216;int&#8217; object is not iterable<\/a><\/li><\/ul><\/li><li><a href=\"#i-6\"><span class=\"toc_number toc_depth_1\">5<\/span> \u307e\u3068\u3081<\/a><\/li><\/ul><\/div>\n<h2><span id=\"Pythonfor\"><span style=\"font-weight: 400;\">Python\u306efor\u30eb\u30fc\u30d7\u306e\u57fa\u672c<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2469 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/43-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/43-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/43.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u307e\u305a\u306f\u3001Python\u306efor\u30eb\u30fc\u30d7\u306e\u57fa\u672c\u3092\u304a\u3055\u3089\u3044\u3057\u307e\u3057\u3087\u3046\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">fruits = [&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;cherry&#8217;]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for fruit in fruits:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0print(fruit)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001<span style=\"text-decoration: underline;\"><strong>\u30ea\u30b9\u30c8 fruits \u306e\u5404\u8981\u7d20\u3092\u9806\u756a\u306b\u53d6\u308a\u51fa\u3057\u3066\u8868\u793a\u3057\u3066\u3044\u307e\u3059<\/strong><\/span>\u3002\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\uff080, 1, 2\u306a\u3069\uff09\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b\uff1f<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"rangelen\"><span style=\"font-weight: 400;\">\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u2460\uff1arange()\u3068len()<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Python\u521d\u5fc3\u8005\u304c\u6700\u521d\u306b\u601d\u3044\u3064\u304f\u306e\u306f\u3001r<span style=\"text-decoration: underline;\"><strong>ange() \u3068 len() \u3092\u4f7f\u3046\u65b9\u6cd5<\/strong><\/span>\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">fruits = [&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;cherry&#8217;]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for i in range(len(fruits)):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0print(i, fruits[i])<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u65b9\u6cd5\u3067\u3082\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3068\u8981\u7d20\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"enumerate\"><span style=\"font-weight: 400;\">\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3068\u8981\u7d20\u3092\u540c\u6642\u306b\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u2461\uff1aenumerate()<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">Python\u3067\u3088\u308a\u30b9\u30de\u30fc\u30c8\u306a\u65b9\u6cd5\u304c<span style=\"text-decoration: underline;\"><strong> enumerate()<\/strong><\/span> \u3092\u4f7f\u3046\u66f8\u304d\u65b9\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">fruits = [&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;cherry&#8217;]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for i, fruit in enumerate(fruits):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0print(i, fruit)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001<span style=\"text-decoration: underline;\"><strong>enumerate(fruits) \u306b\u3088\u3063\u3066 (\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7, \u8981\u7d20) \u306e\u30bf\u30d7\u30eb\u304c\u751f\u6210\u3055\u308c\u3001\u305d\u308c\u3092 i, fruit\u306b\u5206\u89e3\u3057\u3066\u30eb\u30fc\u30d7\u51e6\u7406\u3057\u3066\u3044\u307e\u3059<\/strong><\/span>\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"enumerate-2\"><span style=\"font-weight: 400;\">enumerate() \u306e\u4ed5\u7d44\u307f<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2470 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/44-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/44-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/44.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"text-decoration: underline;\"><strong>enumerate() \u306f\u3001\u30a4\u30c6\u30e9\u30d6\u30eb\uff08\u7e70\u308a\u8fd4\u3057\u53ef\u80fd\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff09\u3092\u53d7\u3051\u53d6\u308a\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3068\u8981\u7d20\u306e\u30da\u30a2\u3092\u8fd4\u3059\u30a4\u30c6\u30ec\u30fc\u30bf\u3092\u751f\u6210\u3057\u307e\u3059<\/strong><\/span>\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">list(enumerate([&#8216;a&#8217;, &#8216;b&#8217;, &#8216;c&#8217;]))<\/span><\/p>\n<p><span style=\"font-weight: 400;\"># \u51fa\u529b: [(0, &#8216;a&#8217;), (1, &#8216;b&#8217;), (2, &#8216;c&#8217;)]<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u3088\u3046\u306b\u3001enumerate() \u306f\u5185\u90e8\u7684\u306b [(0, &#8216;a&#8217;), (1, &#8216;b&#8217;), (2, &#8216;c&#8217;)] \u306e\u3088\u3046\u306a\u30bf\u30d7\u30eb\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u3063\u3066\u3044\u308b\u3068\u8003\u3048\u308b\u3068\u7406\u89e3\u3057\u3084\u3059\u3044\u3067\u3057\u3087\u3046\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"start\"><span style=\"font-weight: 400;\">start\u5f15\u6570\u3067\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\">enumerate() \u306b\u306f start \u5f15\u6570\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u306e\u958b\u59cb\u5024\u3092\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">fruits = [&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;cherry&#8217;]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for i, fruit in enumerate(fruits, start=1):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0print(i, fruit)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u304c 1 \u304b\u3089\u59cb\u307e\u308a\u307e\u3059\u3002\u30e6\u30fc\u30b6\u30fc\u306b\u8868\u793a\u3059\u308b\u969b\u306a\u3069\u30010\u59cb\u307e\u308a\u3067\u306f\u306a\u304f1\u59cb\u307e\u308a\u306b\u3057\u305f\u3044\u5834\u9762\u3067\u4fbf\u5229\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"enumerate-3\"><span style=\"font-weight: 400;\">\u5b9f\u52d9\u3067\u5f79\u7acb\u3064enumerate\u306e\u6d3b\u7528\u4f8b<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2471 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/45-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/45-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/45.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u3053\u304b\u3089\u306f\u3001\u696d\u52d9\u3084\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3067\u306e\u5177\u4f53\u7684\u306a\u6d3b\u7528\u30b7\u30fc\u30f3\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"i\"><span style=\"font-weight: 400;\">\u30ed\u30b0\u51fa\u529b\u306b\u884c\u756a\u53f7\u3092\u4ed8\u3051\u308b<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #0000ff;\">log_messages = [<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0&#8220;Server started&#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0&#8220;Database connected&#8221;,<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0&#8220;User logged in&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for line_number, message in enumerate(log_messages, start=1):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0print(f&#8221;[Line {line_number}] {message}&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u51fa\u529b:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">[Line 1] Server started<\/span><\/p>\n<p><span style=\"font-weight: 400;\">[Line 2] Database connected<\/span><\/p>\n<p><span style=\"font-weight: 400;\">[Line 3] User logged in<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u30c7\u30d0\u30c3\u30b0\u3084\u30ed\u30b0\u89e3\u6790\u3067<\/span><span style=\"text-decoration: underline;\"><b>\u3069\u306e\u884c\u306e\u51e6\u7406\u306a\u306e\u304b<\/b><\/span><span style=\"font-weight: 400;\">\u3092\u660e\u78ba\u306b\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"i-2\"><span style=\"font-weight: 400;\">\u30e6\u30fc\u30b6\u30fc\u5165\u529b\u306e\u691c\u8a3c<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #0000ff;\">usernames = [&#8220;alice&#8221;, &#8220;&#8221;, &#8220;charlie&#8221;]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for idx, name in enumerate(usernames, start=1):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0if not name:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f&#8221;{idx}\u756a\u76ee\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u304c\u672a\u5165\u529b\u3067\u3059&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u51fa\u529b:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2\u756a\u76ee\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u304c\u672a\u5165\u529b\u3067\u3059<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u30e6\u30fc\u30b6\u30fc\u3054\u3068\u306e\u4f4d\u7f6e\u3092\u3059\u3050\u306b\u7279\u5b9a\u3067\u304d\u308b\u305f\u3081\u3001\u30a8\u30e9\u30fc\u4fee\u6b63\u304c\u697d\u306b\u306a\u308a\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"i-3\"><span style=\"font-weight: 400;\">\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u884c\u756a\u53f7\u3092\u4ed8\u4e0e\u3057\u3066\u767b\u9332<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #0000ff;\">import sqlite3<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">data = [&#8220;Tokyo&#8221;, &#8220;Osaka&#8221;, &#8220;Nagoya&#8221;]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">conn = sqlite3.connect(&#8220;:memory:&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">cursor = conn.cursor()<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">cursor.execute(&#8220;CREATE TABLE cities (id INTEGER, name TEXT)&#8221;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for city_id, city_name in enumerate(data, start=1):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0cursor.execute(&#8220;INSERT INTO cities VALUES (?, ?)&#8221;, (city_id, city_name))<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">conn.commit()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u81ea\u52d5\u7684\u306b\u9023\u756aID\u3092\u4ed8\u4e0e\u3067\u304d\u308b\u305f\u3081\u3001\u30d7\u30e9\u30a4\u30de\u30ea\u30ad\u30fc\u306e\u8a2d\u5b9a\u304c\u5bb9\u6613\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"i-4\"><span style=\"font-weight: 400;\">\u30d5\u30a1\u30a4\u30eb\u8aad\u307f\u8fbc\u307f\u6642\u306e\u884c\u756a\u53f7\u7ba1\u7406<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #0000ff;\">with open(&#8220;sample.txt&#8221;, encoding=&#8221;utf-8&#8243;) as f:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0for line_number, line in enumerate(f, start=1):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f&#8221;{line_number}: {line.strip()}&#8221;)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u30a8\u30e9\u30fc\u767a\u751f\u6642\u306b<\/span><span style=\"text-decoration: underline;\"><b>\u3069\u306e\u884c\u306e\u30c7\u30fc\u30bf\u306b\u554f\u984c\u304c\u3042\u308b\u304b<\/b><\/span><span style=\"font-weight: 400;\">\u7279\u5b9a\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"enumerate-4\"><span style=\"font-weight: 400;\">\u30cd\u30b9\u30c8\u3057\u305f\u30eb\u30fc\u30d7\u3067\u306eenumerate<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #0000ff;\">matrix = [<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0[1, 2, 3],<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0[4, 5, 6],<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0[7, 8, 9]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for row_index, row in enumerate(matrix, start=1):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0for col_index, value in enumerate(row, start=1):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(f&#8221;({row_index},{col_index}) = {value}&#8221;)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">2\u6b21\u5143\u30ea\u30b9\u30c8\u3084\u5165\u308c\u5b50\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u3067\u3082<\/span>enumerate\u306f\u6d3b\u8e8d\u3057\u307e\u3059<b>\u3002<\/b><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"i-5\"><span style=\"font-weight: 400;\">\u3088\u304f\u3042\u308b\u30df\u30b9\u3068\u6ce8\u610f\u70b9<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2472 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/46-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/46-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/46.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3><\/h3>\n<h3><span id=\"too_many_values_to_unpack\"><span style=\"font-weight: 400;\">too many values to unpack \u30a8\u30e9\u30fc<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for index, value, extra in enumerate([&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;]):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0pass<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>\u539f\u56e0<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">enumerate() \u304c\u8fd4\u3059\u306e\u306f (index, value) \u306e2\u3064\u3060\u3051<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u5909\u6570\u30923\u3064\u3067\u53d7\u3051\u53d6\u308b\u3068\u30a8\u30e9\u30fc<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3><span id=\"TypeError_8216int8217_object_is_not_iterable\"><span style=\"font-weight: 400;\">TypeError: &#8216;int&#8217; object is not iterable<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #0000ff;\">for i, v in enumerate(100):<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #0000ff;\">\u00a0\u00a0\u00a0\u00a0pass<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>\u539f\u56e0<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">enumerate \u306e\u5f15\u6570\u306f <\/span>\u30a4\u30c6\u30e9\u30d6\u30eb\uff08\u53cd\u5fa9\u53ef\u80fd\uff09\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<span style=\"font-weight: 400;\"> \u3067\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u6574\u6570\u306a\u3069\u306f\u305d\u306e\u307e\u307e\u6e21\u305b\u306a\u3044<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2><span id=\"i-6\"><span style=\"font-weight: 400;\">\u307e\u3068\u3081<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Python\u306e<\/span>enumerate()\u306f\u3001\u5358\u7d14\u306a\u30eb\u30fc\u30d7\u3092\u3088\u308a\u30b7\u30f3\u30d7\u30eb\u304b\u3064\u52b9\u7387\u7684\u306b\u66f8\u3051\u308b\u4fbf\u5229\u306a\u95a2\u6570\u3067\u3059<b>\u3002<\/b><span style=\"font-weight: 400;\">\u7279\u306b\u3001<\/span>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3068\u5024\u306e\u4e21\u65b9\u304c\u5fc5\u8981\u306a\u5834\u9762\u3067\u306f\u5fc5\u9808\u30ec\u30d9\u30eb\u3068\u8a00\u3063\u3066\u3082\u904e\u8a00\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<span style=\"font-weight: 400;\">enumerate() \u3092\u4f7f\u3048\u3070\u3001Python\u306efor\u30eb\u30fc\u30d7\u304c\u3088\u308a\u7c21\u6f54\u3067\u8aad\u307f\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u3068\u8981\u7d20\u3092\u540c\u6642\u306b\u53d6\u5f97\u3059\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u51e6\u7406\u306e\u5e45\u304c\u5e83\u304c\u308a\u3001\u5b9f\u52d9\u3067\u3082\u5f79\u7acb\u3064\u5834\u9762\u304c\u591a\u304f\u3042\u308a\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Python\u521d\u5fc3\u8005\u306e\u65b9\u306f\u3001\u307e\u305a\u306f\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u3092\u30de\u30b9\u30bf\u30fc\u3057\u3001\u5c11\u3057\u305a\u3064\u5fdc\u7528\u4f8b\u306b\u3082\u30c1\u30e3\u30ec\u30f3\u30b8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3068\u52b9\u7387\u3092\u9ad8\u3081\u308b\u305f\u3081\u306b\u3001enumerate() \u306f\u305c\u3072\u7fd2\u5f97\u3057\u3066\u304a\u304d\u305f\u3044\u95a2\u6570\u306e\u3072\u3068\u3064\u3067\u3059\u3002<\/span><\/p>\n<p>\u3088\u308a\u8907\u96d1\u306a\u696d\u52d9\u306e\u81ea\u52d5\u5316\u3084\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u3067\u304a\u56f0\u308a\u306e\u3053\u3068\u304c\u3042\u308a\u307e\u3057\u305f\u3089\u3001\u305c\u3072\u304a\u6c17\u8efd\u306b<span style=\"color: #0000ff;\"><strong><a style=\"color: #0000ff;\" href=\"https:\/\/softasia.jp\/#contact\">3ink<\/a><\/strong><\/span>\u3078\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Python\u3067\u30ea\u30b9\u30c8\u3084\u30bf\u30d7\u30eb\u306a\u3069\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u6271\u3046\u969b\u3001\u300c\u8981\u7d20\u300d\u3068\u300c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u756a\u53f7\u300d\u3092\u540c\u6642\u306b\u53d6\u5f97\u3057\u305f\u3044\u5834\u9762\u306f\u591a\u3005\u3042\u308a\u307e\u3059\u3002\u305d\u3093\u306a\u3068\u304d\u306b\u4fbf\u5229\u306a\u306e\u304c\u3001Python\u306e\u7d44\u307f\u8fbc\u307f\u95a2\u6570 enumerate() \u3067\u3059\u3002  [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":2460,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1,9],"tags":[],"jetpack_featured_media_url":"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-9.png","_links":{"self":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts\/2432"}],"collection":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/comments?post=2432"}],"version-history":[{"count":19,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts\/2432\/revisions"}],"predecessor-version":[{"id":2806,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts\/2432\/revisions\/2806"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/media\/2460"}],"wp:attachment":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/media?parent=2432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/categories?post=2432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/tags?post=2432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}