{"id":180,"date":"2017-01-25T11:34:55","date_gmt":"2017-01-25T02:34:55","guid":{"rendered":"http:\/\/www.python.ambitious-engineer.com\/?p=180"},"modified":"2021-09-12T22:01:43","modified_gmt":"2021-09-12T13:01:43","slug":"dictionary%e8%be%9e%e6%9b%b8%e5%9e%8b%e3%81%ae%e5%9f%ba%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/www.python.ambitious-engineer.com\/archives\/180","title":{"rendered":"dictionary(\u8f9e\u66f8)\u578b"},"content":{"rendered":"<p>Python\u3067\u30de\u30c3\u30d7\u578b\u3068\u3057\u3066\u6271\u308f\u308c\u308b\u3082\u306e\u306e\u3046\u3061\u3001\u57fa\u672c\u7684\u306a\u7d44\u8fbc\u307f\u306e\u578b\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u306bdictionary\u578b\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30da\u30fc\u30b8\u3067\u306fdictionary\u578b\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<h2>dictionary\u578b\u306e\u57fa\u672c<\/h2>\n<h3>dictionary\u578b\u3068\u306f<\/h3>\n<p>Python\u306b\u9650\u3089\u305a\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067dictionary\u3068\u3044\u3046\u3068\u3001\u30ad\u30fc\u306b\u5bfe\u3057\u3066\u5024\u304c\u8a2d\u5b9a\u3055\u308c\u305f\u8868\u306e\u3088\u3046\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u3092\u6307\u3057\u307e\u3059\u3002\u65e5\u672c\u8a9e\u8a33\u306e\u8f9e\u66f8\u3084\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u306b\u3088\u3063\u3066\u306f\u30cf\u30c3\u30b7\u30e5\u3068\u547c\u3076\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>dictionary\u578b\u304c\u9069\u3057\u3066\u3044\u307e\u3059\u4f8b\u3068\u3057\u3066\u3001\u5546\u54c1\u30b3\u30fc\u30c9\u3068\u5546\u54c1\u540d\u3092\u683c\u7d0d\u3057\u305f\u3044\u5834\u5408\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002\u3053\u306e\u5834\u5408\u3001\u5546\u54c1\u30b3\u30fc\u30c9\u304c\u30ad\u30fc\u3001\u5546\u54c1\u540d\u304c\u5024\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<a href=\"http:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2017\/01\/dict_image-e1542285672733.png\"><img loading=\"lazy\" src=\"http:\/\/www.python.ambitious-engineer.com\/wp-content\/uploads\/2017\/01\/dict_image-e1542285672733.png\" alt=\"\" width=\"200\" height=\"138\" class=\"alignnone size-full wp-image-2012\" \/><\/a>\n<p>\u4ee5\u964d\u3001dictionary\u578b\u3084dictionary\u578b\u5909\u6570\u3092\u5358\u306b\u8f9e\u66f8\u3068\u8a18\u8ff0\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u8f9e\u66f8\u306e\u521d\u671f\u5316<\/h3>\n<p>\u3067\u306f\u65e9\u901fdictionary\u578b\u5909\u6570\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u521d\u671f\u5316\u306f\u4e2d\u62ec\u5f27\u306e\u4e2d\u306b\u3001\u30b3\u30ed\u30f3\u3067\u533a\u5207\u3063\u305f\u30ad\u30fc\u3068\u5024\u306e\u7d44\u3092\u30ab\u30f3\u30de\u533a\u5207\u308a\u3067\u5217\u6319\u3057\u307e\u3059\u3002\u30b5\u30f3\u30d7\u30eb\u3067\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd = {'key1': 110, 'key2': 270, 'key3': 350}\r\nprint(d) # {'key1': 110, 'key2': 270, 'key3': 350}\r\n\r\n<\/pre>\n<h3>\u5024\u3078\u306e\u30a2\u30af\u30bb\u30b9<\/h3>\n<p>\u5024\u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u65b9\u6cd5\u306f2\u901a\u308a\u3042\u308a\u307e\u3059\u3002\u3072\u3068\u3064\u306f\u30ea\u30b9\u30c8\u3068\u540c\u69d8\u306b\u30ad\u30fc\u3092\u5927\u62ec\u5f27\u3067\u6dfb\u5b57\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002\u3053\u306e\u65b9\u6cd5\u306f\u3001\u5b58\u5728\u3057\u306a\u3044\u30ad\u30fc\u3092\u6307\u5b9a\u3059\u308b\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd= {'key1': 110, 'key2': 270, 'key3': 350}\r\nprint(d['key1']) # 110\u304c\u51fa\u529b\u3055\u308c\u308b\r\nprint(d['hoge']) # KeyError\u304c\u767a\u751f\u3059\u308b\r\n<\/pre>\n<p>\u307e\u305f\u3001get\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306f\u4e0a\u306e\u30b5\u30f3\u30d7\u30eb\u3092get\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u305f\u3082\u306e\u306b\u66f8\u304d\u306a\u304a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd = {'key1': 110, 'key2': 270, 'key3': 350}\r\nprint(d.get('key1')) # 110\u304c\u51fa\u529b\u3055\u308c\u308b\r\nprint(d.get('hoge')) # None\u304c\u51fa\u529b\u3055\u308c\u308b\r\n<\/pre>\n<p>KeyError\u304c\u767a\u751f\u305b\u305aNone\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002\u30ad\u30fc\u304c\u306a\u3044\u5834\u5408\u306bNone\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306b\u4f7f\u3048\u307e\u3059\u3002\u4e00\u65b9\u3067\u30ad\u30fc\u304c\u306a\u3044\u5834\u5408\u306f\u30a8\u30e9\u30fc\u3067\u51e6\u7406\u3057\u305f\u3044\u5834\u5408\u306f\u5927\u62ec\u5f27\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h3>\u5024\u306e\u66f4\u65b0<\/h3>\n<p>\u6dfb\u5b57\u3067\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3082\u306e\u306b\u5bfe\u3057\u3066\u5024\u3092\u4ee3\u5165\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u66f4\u65b0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001key1\u3068\u3044\u3046\u30ad\u30fc\u306b\u5bfe\u5fdc\u3059\u308b\u5024110\u3092200\u306b\u66f4\u65b0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd = {'key1': 110, 'key2': 270, 'key3': 350}\r\nd['key1'] = 200 # 200\u306b\u66f4\u65b0\r\nprint(d['key1']) # \u66f4\u65b0\u5f8c\u306e200\u304c\u51fa\u529b\u3055\u308c\u308b\r\n\r\n<\/pre>\n<h3>\u5024\u306e\u8ffd\u52a0<\/h3>\n<p>\u65b0\u305f\u306a\u30ad\u30fc\u3067\u66f4\u65b0\u3068\u540c\u69d8\u306b\u4ee3\u5165\u3059\u308b\u3068\u65b0\u305f\u306a\u8981\u7d20\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3002\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001key4\u3068\u3044\u3046\u30ad\u30fc\u306b\u5bfe\u3057\u3066\u5024400\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd = {'key1': 110}\r\nd['key4'] = 400 # \u5024\u3092\u8ffd\u52a0\r\nprint(d) # {'key1': 110, 'key4': 400}\r\n<\/pre>\n<h3>dict()\u306b\u3088\u308b\u751f\u6210<\/h3>\n<p>\u82e5\u5e72\u8aac\u660e\u304c\u524d\u5f8c\u3057\u307e\u3059\u304cdictionary\u578b\u306e\u751f\u6210\u3067\u3082\u3046\u4e00\u3064\u3001\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u306edict()\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u5834\u5408\u306f\u4e00\u65e6\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u3066\u5f8c\u304b\u3089\u5024\u3092\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd = dict()\r\nd['key1'] = 110\r\nd['key2'] = 270\r\nd['key3'] = 350\r\nprint(d) # {'key1': 110, 'key2': 270, 'key3': 350}\r\n\r\n<\/pre>\n<p>\u307e\u305f\u3001\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u8f9e\u66f8\u3092\u6307\u5b9a\u3059\u308b\u3068\u540c\u3058\u8f9e\u66f8\u3092\u751f\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd1 = {'key1': 110, 'key2': 270, 'key3': 350}\r\nd2 = dict(d1)\r\nprint(d2) # {'key2': 270, 'key1': 110, 'key3': 350}\r\n<\/pre>\n<h3>dictionary\u306e\u8981\u7d20\u6570<\/h3>\n<p>dictionary\u306e\u8981\u7d20\u6570\u3092\u78ba\u8a8d\u3059\u308b\u5834\u5408\u306f\u30ea\u30b9\u30c8\u3068\u540c\u69d8\u306blen\u95a2\u6570\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nd = {'key1': 110, 'key2': 270, 'key3': 350}\r\nprint(len(d)) # \u8981\u7d20\u6570\u306e3\u304c\u51fa\u529b\u3055\u308c\u308b\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python\u3067\u30de\u30c3\u30d7\u578b\u3068\u3057\u3066\u6271\u308f\u308c\u308b\u3082\u306e\u306e\u3046\u3061\u3001\u57fa\u672c\u7684\u306a\u7d44\u8fbc\u307f\u306e\u578b\u3067\u63d0\u4f9b\u3055\u308c\u3066\u3044\u308b\u3082\u306e\u306bdictionary\u578b\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30da\u30fc\u30b8\u3067\u306fdictionary\u578b\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002 dictionary\u578b\u306e\u57fa\u672c dicti...<\/p>\n","protected":false},"author":1,"featured_media":3417,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[48,81],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/180"}],"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=180"}],"version-history":[{"count":11,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"predecessor-version":[{"id":3418,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/posts\/180\/revisions\/3418"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media\/3417"}],"wp:attachment":[{"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.python.ambitious-engineer.com\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}