{"id":4828,"date":"2023-11-14T12:01:11","date_gmt":"2023-11-14T03:01:11","guid":{"rendered":"https:\/\/417.run\/?p=4828"},"modified":"2023-11-14T12:01:11","modified_gmt":"2023-11-14T03:01:11","slug":"enum","status":"publish","type":"post","link":"https:\/\/417.run\/pg\/python\/enum\/","title":{"rendered":"python\u3067enum\u3092\u4f7f\u3046\u65b9\u6cd5"},"content":{"rendered":"    <div class=\"say right\">\n      <div class=\"chatting\"><div class=\"sc\">python\u3067enum\u3092\u4f7f\u3046\u65b9\u6cd5\u3042\u308b\uff1f<\/div><\/div>\n      <p class=\"faceicon\"><img decoding=\"async\" src=\"https:\/\/417.run\/wp-content\/uploads\/2023\/02\/\u666e\u901a.png\" width=\"110\"><span>417<\/span><\/p>\n    <\/div>\n<p>Python\u3067\u306f\u3001enum \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u5217\u6319\u578b\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306fPython 3.4\u4ee5\u964d\u3067\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002<\/p>\n    <div class=\"say right\">\n      <div class=\"chatting\"><div class=\"sc\">\u3048\uff01\uff1f\u305d\u3046\u306a\u306e\uff1f<\/div><\/div>\n      <p class=\"faceicon\"><img decoding=\"async\" src=\"https:\/\/417.run\/wp-content\/uploads\/2023\/02\/\u9a5a.png\" width=\"110\"><span>417<\/span><\/p>\n    <\/div>\n    <div class=\"say right\">\n      <div class=\"chatting\"><div class=\"sc\">\u4f7f\u3044\u65b9\u6559\u3048\u3066\uff01<\/div><\/div>\n      <p class=\"faceicon\"><img decoding=\"async\" src=\"https:\/\/417.run\/wp-content\/uploads\/2023\/02\/\u7b11.jpg\" width=\"110\"><span>417<\/span><\/p>\n    <\/div>\n<p>Python\u3067enum\uff08\u5217\u6319\u578b\uff09\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3092\u5177\u4f53\u7684\u306b\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001enum \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u3001Enum \u30af\u30e9\u30b9\u3092\u7d99\u627f\u3057\u3066\u65b0\u3057\u3044\u5217\u6319\u578b\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u306e\u5217\u6319\u578b\u306e\u30e1\u30f3\u30d0\u30fc\u306f\u5927\u6587\u5b57\u3067\u540d\u524d\u3092\u4ed8\u3051\u308b\u306e\u304c\u4e00\u822c\u7684\u3067\u3059\u3002\u4ee5\u4e0b\u306f\u305d\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\u306e\u4f8b\u3067\u3059\uff1a<\/p>\n<pre><code class=\"language-python\">from enum import Enum\n\nclass Color(Enum):\n    RED = 1\n    GREEN = 2\n    BLUE = 3\n\n# \u5217\u6319\u578b\u306e\u4f7f\u7528\ncolor = Color.RED\nprint(color)  # Color.RED\n\n# \u5217\u6319\u578b\u306e\u5024\u306e\u53d6\u5f97\nprint(color.value)  # 1\n\n# \u5217\u6319\u578b\u306e\u540d\u524d\u306e\u53d6\u5f97\nprint(color.name)  # &#039;RED&#039;\n\n# \u5217\u6319\u578b\u306e\u30eb\u30fc\u30d7\u51e6\u7406\nfor c in Color:\n    print(c)<\/code><\/pre>\n<p>\u3053\u306e\u4f8b\u3067\u306f\u3001Color \u3068\u3044\u3046\u540d\u524d\u306e\u5217\u6319\u578b\u3092\u4f5c\u6210\u3057\u30013\u3064\u306e\u8272\uff08RED, GREEN, BLUE\uff09\u3092\u30e1\u30f3\u30d0\u30fc\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002\u305d\u308c\u305e\u308c\u306e\u30e1\u30f3\u30d0\u30fc\u306b\u306f\u6574\u6570\u5024\u304c\u5272\u308a\u5f53\u3066\u3089\u308c\u3066\u3044\u307e\u3059\u3002\u5217\u6319\u578b\u306e\u30e1\u30f3\u30d0\u30fc\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u3001Color.RED \u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002\u307e\u305f\u3001.value \u5c5e\u6027\u3092\u4f7f\u3063\u3066\u3001\u305d\u306e\u5024\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u540c\u69d8\u306b\u3001.name \u5c5e\u6027\u3067\u30e1\u30f3\u30d0\u30fc\u306e\u540d\u524d\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u5217\u6319\u578b\u306f\u30eb\u30fc\u30d7\u3067\u56de\u3059\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5b9a\u7fa9\u3057\u305f\u3059\u3079\u3066\u306e\u5217\u6319\u578b\u306e\u30e1\u30f3\u30d0\u30fc\u3092\u9806\u306b\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u3067\u306f\u3001enum \u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u4f7f\u7528\u3057\u3066\u5217\u6319\u578b\u3092\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u30e2\u30b8\u30e5\u30fc\u30eb\u306fPython 3.4\u4ee5\u964d\u3067\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002 Python\u3067enum\uff08\u5217\u6319\u578b\uff09\u3092\u4f7f\u7528\u3059\u308b\u65b9\u6cd5\u3092\u5177\u4f53\u7684\u306b\u8aac\u660e\u3057\u307e\u3059\u3002 \u307e\u305a\u3001enum \u30e2\u30b8\u30e5 &#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":{"0":"post-4828","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python","7":"nothumb"},"_links":{"self":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/4828"}],"collection":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/comments?post=4828"}],"version-history":[{"count":3,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/4828\/revisions"}],"predecessor-version":[{"id":4831,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/posts\/4828\/revisions\/4831"}],"wp:attachment":[{"href":"https:\/\/417.run\/wp-json\/wp\/v2\/media?parent=4828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/categories?post=4828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/417.run\/wp-json\/wp\/v2\/tags?post=4828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}