{"id":475,"date":"2019-01-06T18:47:52","date_gmt":"2019-01-06T09:47:52","guid":{"rendered":"https:\/\/www.nblog09.com\/w\/?p=475"},"modified":"2021-06-13T09:33:56","modified_gmt":"2021-06-13T00:33:56","slug":"python-class-basic","status":"publish","type":"post","link":"https:\/\/www.nblog09.com\/w\/2019\/01\/06\/python-class-basic\/","title":{"rendered":"Python\u30af\u30e9\u30b9\u306e\u5b9a\u7fa9\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u3001\u30e1\u30bd\u30c3\u30c9\u3001\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf(__init__)\u3001self\u306e\u610f\u5473\u3001Python\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u306e\u57fa\u672c"},"content":{"rendered":"<h2 class=\"title-border\"><strong>\u30af\u30e9\u30b9\u5b9a\u7fa9\u306e\u65b9\u6cd5<\/strong><\/h2>\n<p>python\u306f<span class=\"pink_span\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e<\/span>\u3067\u3042\u308a\u3001\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3057\u3066<span class=\"pink_span\">\u5c5e\u6027\uff08\u30d7\u30ed\u30d1\u30c6\u30a3\uff09<\/span>\u3068<span class=\"pink_span\">\u30e1\u30bd\u30c3\u30c9<\/span>\u3092\u6301\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u30af\u30e9\u30b9\u3068\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u96db\u5f62\u3067\u3042\u308b\u3002<\/p>\n<p>\u5b9f\u969b\u306bpython\u3067\u30af\u30e9\u30b9\u3067\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3002<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>\u30af\u30e9\u30b9\u3068\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5b9a\u7fa9<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nclass SampleClass:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;value=5\n<\/div>\n<ul>\n<li>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210\u3057\u3066\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9<\/li>\n<\/ul>\n<div class=\"programming-inside\">\ns = SampleClass() <strong># \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210<\/strong><br \/>\nprint(s.value) <strong># 5\u3068\u8868\u793a(\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9)<\/strong><br \/>\n<\/span>\n<\/div>\n<ul>\n<li>\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3059\u308b\u304c\u4e2d\u306b\u8a18\u8ff0\u3057\u306a\u3044\u5834\u5408pass\u3068\u3059\u308b<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nclass SampleClass:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;pass<br \/>\n<\/span>\n<\/div>\n<\/div>\n<h2 class=\"title-border\"><strong>\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5909\u66f4\u3068\u524a\u9664<\/strong><\/h2>\n<p>\u30af\u30e9\u30b9\u304b\u3089\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u4f5c\u6210\u3057\u3066\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u5024\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>\u30af\u30e9\u30b9\u3068\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5b9a\u7fa9<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nclass SampleClass:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;value=5\n<\/div>\n<ul>\n<li>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210\u3057\u3066\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5024\u3092\u5909\u66f4<\/li>\n<\/ul>\n<div class=\"programming-inside\">\ns = SampleClass()<br \/>\ns.value = 6 <strong># \u5024\u30925\u304b\u30896\u306b\u5909\u66f4<\/strong><br \/>\nprint(s.value) <strong># 6\u3068\u8868\u793a<\/strong><br \/>\n<\/span>\n<\/div>\n<ul>\n<li>\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u524a\u9664<\/li>\n<\/ul>\n<div class=\"programming-inside\">\ndel s.value <strong># \u30d7\u30ed\u30d1\u30c6\u30a3value\u524a\u9664<\/strong><br \/>\ndel s <strong># \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9s\u524a\u9664<\/strong><br \/>\n<\/span>\n<\/div>\n<\/div>\n<h2 class=\"title-border\"><strong>\u30e1\u30bd\u30c3\u30c9\u306e\u4f5c\u6210\u3068\u5b9f\u884c<\/strong><\/h2>\n<p>\u6b21\u306b\u30e1\u30bd\u30c3\u30c9\u3092\u5b9a\u7fa9\u3059\u308b\u65b9\u6cd5\u3068\u305d\u308c\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8a18\u8ff0\u3059\u308b<\/p>\n<p>\u30e1\u30bd\u30c3\u30c9\u3068\u306f\u30af\u30e9\u30b9\u306e\u4e2d\u306b\u8a18\u8ff0\u3059\u308b\u95a2\u6570\u3067\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u3078\u306e\u30a2\u30af\u30bb\u30b9\u3082\u542b\u3093\u3060\u4e00\u9023\u306e\u51e6\u7406\u3092\u307e\u3068\u3081\u305f\u3082\u306e\u3067\u3042\u308b\u3002<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>\u30af\u30e9\u30b9\u3068\u30e1\u30bd\u30c3\u30c9\u306e\u5b9a\u7fa9<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nclass PrintClass:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;value = 20 <strong># \u30d7\u30ed\u30d1\u30c6\u30a3<\/strong><\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;def print_word(self, str): <strong># \u30e1\u30bd\u30c3\u30c9\u306e\u5b9a\u7fa9\u3001\u7b2c1\u5f15\u6570\u306fself\u3068\u3059\u308b<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(str) <\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;def print_value(self):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(self.value) <strong># self.value\u3068\u3057\u3066\u3001value\u3092\u53c2\u7167\u3059\u308b<\/strong><\/p>\n<p>p1= PrintClass()<br \/>\np1.print_word(\"Hello\")<br \/>\n<strong># print_class\u306eprint_word\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3002<?strong><br \/>\n\u5f15\u6570self\u306b\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u81ea\u8eab(p1)\u304c\u5165\u308a\u3001\u5f15\u6570str\u306b\u306f\"Hello\"\u3092\u6e21\u3057\u3066\u5b9f\u884c\u3055\u308c\u308b <\/strong><\/p>\n<p>p1.print_value() <strong># print(self.value)\u304c\u5b9f\u884c\u3055\u308c\u300120\u304c\u8868\u793a\u3055\u308c\u308b<\/strong><\/p>\n<p>a.value = 50 <strong># value\u306e\u5024\u3092\u5909\u66f4<\/strong><br \/>\na.print_value() <strong># print(self.value)\u306e\u7d50\u679c\u300150\u304c\u8868\u793a\u3055\u308c\u308b<\/strong>\n<\/div>\n<\/div>\n<h2 class=\"title-border\"><strong>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30c8(__init__)\u306e\u5b9a\u7fa9<\/strong><\/h2>\n<p>\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3068\u3001\u307e\u305a\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u3092\u5b9a\u7fa9\u3059\u308b\u306e\u304c\u4e00\u822c\u7684\u3067\u3042\u308b\u3002<br \/>\n\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf\u306f\u3001\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u4f5c\u6210\u6642\u306b\u547c\u3073\u51fa\u3055\u308c\u308b\u7279\u6b8a\u30e1\u30bd\u30c3\u30c9\u3067\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u521d\u671f\u5316\u306a\u3069\u3092\u884c\u3046<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>\u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf(__init__)\u306e\u5b9a\u7fa9<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nclass Person:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self, name, age): <strong># \u30b3\u30f3\u30b9\u30c8\u30e9\u30af\u30bf<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.name = name<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.age = age<\/p>\n<p>p1= Person(\"Taro\", 20) <strong># __init__\u304c\u547c\u3073\u51fa\u3055\u308c\u3001name\u3068age\u304cTaro, 20\u3067\u521d\u671f\u5316\u3055\u308c\u308b<\/strong><br \/>\nprint(p1.name) <strong># Taro<\/strong><br \/>\nprint(p1.age) <strong># 20<\/strong><\/p>\n<\/div>\n<\/div>\n<h2 class=\"title-border\"><strong>self\u3068\u3044\u3046\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u4f55\u306a\u306e\u304b\uff1f<\/strong><\/h2>\n<p>\u3053\u3053\u307e\u3067\u767b\u5834\u3057\u3066\u304d\u305f\u30e1\u30bd\u30c3\u30c9\u306e\u7b2c\u4e00\u5f15\u6570self\u3068\u3044\u3046\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u3001\u73fe\u5728\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3078\u306e\u53c2\u7167\u3092\u8868\u3059\u3002<br \/>\n\u30af\u30e9\u30b9\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3084\u30e1\u30bd\u30c3\u30c9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u969b\u306b\u7528\u3044\u308b\u3002<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>\u30af\u30e9\u30b9\u3068self\u306e\u610f\u5473<\/li>\n<\/ul>\n<div class=\"programming-inside\">\nclass Person:<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self, name, age): <strong># \u7b2c1\u5f15\u6570\u306eself\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3078\u306e\u53c2\u7167<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.name = name <strong>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306ename\u306b\u5f15\u6570name\u3092\u8a2d\u5b9a<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.age = age<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;def print_name(self):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(self.name) <strong># \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306ename\u306b\u30a2\u30af\u30bb\u30b9<\/strong><\/p>\n<p>p1= Person(\"Taro\", 20) <strong># __init__\u304c\u547c\u3073\u51fa\u3055\u308c\u308b(self\u306bp1\u3001name\u306bTaro\u3001age\u306b20\u3092\u8a2d\u5b9a\u3057\u3066\u5b9f\u884c)<\/strong><br \/>\nprint(p1.name) <strong># Taro<\/strong><br \/>\nprint(p1.age) <strong># 20<\/strong><br \/>\np1.print_name() <strong># Taro\u3068\u8868\u793a\u3055\u308c\u308b<\/strong>\n<\/div>\n<\/div>\n<div class=\"customized-adsense\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u30af\u30e9\u30b9\u5b9a\u7fa9\u306e\u65b9\u6cd5 python\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e\u3067\u3042\u308a\u3001\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3057\u3066\u5c5e\u6027\uff08\u30d7\u30ed\u30d1\u30c6\u30a3\uff09\u3068\u30e1\u30bd\u30c3\u30c9\u3092\u6301\u3063\u3066\u3044\u308b\u3002 \u30af\u30e9\u30b9\u3068\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306e\u96db\u5f62\u3067\u3042\u308b\u3002 \u5b9f\u969b\u306bpython\u3067\u30af\u30e9\u30b9\u3067\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u5b9a\u7fa9\u3059 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":243,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_uag_custom_page_level_css":"","_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[9,219],"tags":[101,102,14,100],"class_list":{"0":"post-475","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"category-it-programming","9":"tag-class","10":"tag-method","11":"tag-python","12":"tag-100","13":"entry"},"uagb_featured_image_src":{"full":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",699,480,false],"thumbnail":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480-150x150.jpg",150,150,true],"medium":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480-300x206.jpg",300,206,true],"medium_large":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",699,480,false],"large":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",699,480,false],"1536x1536":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",699,480,false],"2048x2048":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",699,480,false],"home-middle":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",510,350,false],"home-top":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",612,420,false],"sidebar-thumbnail":["https:\/\/www.nblog09.com\/w\/wp-content\/uploads\/2018\/12\/road-220058__480.jpg",100,69,false]},"uagb_author_info":{"display_name":"9nmatsumoto","author_link":"https:\/\/www.nblog09.com\/w\/author\/9nmatsumoto\/"},"uagb_comment_info":0,"uagb_excerpt":"\u30af\u30e9\u30b9\u5b9a\u7fa9\u306e\u65b9\u6cd5 python\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u6307\u5411\u8a00\u8a9e\u3067\u3042\u308a\u3001\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3057\u3066\u5c5e\u6027\uff08\u30d7\u30ed\u30d1\u30c6\u30a3\uff09\u3068\u30e1\u30bd\u30c3\u30c9\u3092\u6301\u3063&hellip;","_links":{"self":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/comments?post=475"}],"version-history":[{"count":23,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":478,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/475\/revisions\/478"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/media\/243"}],"wp:attachment":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/categories?post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/tags?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}