{"id":418,"date":"2019-01-05T02:52:09","date_gmt":"2019-01-04T17:52:09","guid":{"rendered":"https:\/\/www.nblog09.com\/w\/?p=418"},"modified":"2021-06-12T15:16:09","modified_gmt":"2021-06-12T06:16:09","slug":"python-variable","status":"publish","type":"post","link":"https:\/\/www.nblog09.com\/w\/2019\/01\/05\/python-variable\/","title":{"rendered":"Python\u306e\u95a2\u6570\u3067\u306e\u53ef\u5909\u9577\u5f15\u6570(\u53ef\u5909\u9577\u30bf\u30d7\u30eb\u3001\u8f9e\u66f8)\u306e\u4f7f\u3044\u65b9\u307e\u3068\u3081"},"content":{"rendered":"<h2 class=\"title-border\"><strong>Python\u306e\u95a2\u6570\u3067\u306e\u53ef\u5909\u9577\u5f15\u6570\u306e\u4f7f\u3044\u65b9<\/strong><\/h2>\n<p>python\u3067\u306e\u53ef\u5909\u9577\u5f15\u6570\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b*\u3068**\u3092\u5f15\u6570\u306b\u4ed8\u4e0e\u3057\u3066\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<p><span class=\"pink_span\">def func(*arg1, **arg2):<\/span><\/p>\n<p>*arg1\u306e\u3088\u3046\u306b*\u304c1\u3064\u306e\u5834\u5408\u306f\u3001\u53ef\u5909\u9577\u306e\u30bf\u30d7\u30eb<br \/>\n**arg2\u306e\u3088\u3046\u306b*\u304c2\u3064\u306e\u5834\u5408\u306f\u3001\u53ef\u5909\u9577\u306e\u8f9e\u66f8<br \/>\n\u3068\u306a\u308b<\/p>\n<p>\u5b9f\u969b\u306b\u5229\u7528\u65b9\u6cd5\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<div class=\"programming-gray\">\n<ul>\n<li>\u53ef\u5909\u9577\u30bf\u30d7\u30eb\n<\/li>\n<\/ul>\n<div class=\"programming-inside\">\ndef spam(arg1, *arg2):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"arg1 = {}, arg2 = {}\".format(arg1, arg2)) <strong># arg1\u3068arg2\u3092\u8868\u793a<\/span><\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;print(type(arg2)) <strong># &lt;class 'tuple'&gt;\u304c\u8868\u793a\u3055\u308c\u3001arg2\u304c\u30bf\u30d7\u30eb\u3067\u3042\u308b\u3053\u3068\u304c\u308f\u304b\u308b<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;print(arg2[2]) <strong># arg2\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b92\u306e\u5024\u3092\u8868\u793a<\/strong><\/p>\n<p>spam(3,4,5,5) <strong># 1\u3064\u76ee\u306e\u5f15\u6570\u306farg1,\u6b8b\u308a\u306f<span class=\"codehighlight\">arg2\u306b\u30bf\u30d7\u30eb\u3068\u3057\u3066\u683c\u7d0d<\/span>\u3055\u308c\u3001\"arg1 = 3, arg2 = (4, 5, 5)\"\u3001\"5\"\u3068\u8868\u793a\u3055\u308c\u308b<\/strong>\n<\/div>\n<ul>\n<li>\u53ef\u5909\u9577\u8f9e\u66f8\n<\/li>\n<\/ul>\n<div class=\"programming-inside\">\ndef spam(arg1, **arg2):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"arg1 = {}, arg2 = {}\".format(arg1, arg2)) <strong># arg1\u3068arg2\u3092\u8868\u793a<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;print(type(arg2)) <strong># &lt;class 'dict'&gt;\u304c\u8868\u793a\u3055\u308c\u3001arg2\u304c\u8f9e\u66f8\u578b<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;print(arg2['key1']) <strong># arg2\u306e\u30ad\u30fckey1\u306e\u5024\u3092\u8868\u793a<\/strong><\/p>\n<p>spam(3,key1=5, key2=6) <strong># \"arg1 = 3, arg2 = {'key1': 5, 'key2': 6}\", 5\u3068\u8868\u793a\u3055\u308c\u308b<\/strong>\n<\/div>\n<ul>\n<li>\u53ef\u5909\u9577\u30bf\u30d7\u30eb\u3001\u53ef\u5909\u9577\u8f9e\u66f8\u3092\u4e21\u65b9\u5229\u7528<\/li>\n<\/ul>\n<div class=\"programming-inside\">\ndef spam(arg1, *arg2, **arg3):<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;print(\"arg1 = {}\".format(arg1))<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;for value in arg2: <strong># \u30bf\u30d7\u30ebarg2\u306e\u4e2d\u8eab\u3092\u30eb\u30fc\u30d7\u3067\u8868\u793a<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(value)<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;for key in arg3.keys(): <strong># \u8f9e\u66f8arg3\u306e\u30ad\u30fc\u4e00\u89a7\u3092\u30eb\u30fc\u30d7\u3067\u53d6\u5f97<\/strong><br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(\"key = {}, value = {}\".format(key, arg3[key])) <\/p>\n<p>spam(3,4,5,6,arg3=5, arg4=6)<br \/>\n<strong># 3\u306farg1\u306b\u30014,5,6\u306f\u30bf\u30d7\u30eb(4,5,6)\u3068\u3057\u3066arg2\u306b\u3001{'arg3': 3,'arg4': 6}\u3068\u3057\u3066arg3\u306b\u4ee3\u5165\u3057\u3066\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059<\/strong>\n<\/div>\n<\/div>\n<div class=\"customized-adsense\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python\u306e\u95a2\u6570\u3067\u306e\u53ef\u5909\u9577\u5f15\u6570\u306e\u4f7f\u3044\u65b9 python\u3067\u306e\u53ef\u5909\u9577\u5f15\u6570\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b*\u3068**\u3092\u5f15\u6570\u306b\u4ed8\u4e0e\u3057\u3066\u4f7f\u7528\u3059\u308b\u3002 def func(*arg1, **arg2): *arg1\u306e\u3088\u3046\u306b*\u304c1\u3064\u306e\u5834\u5408\u306f\u3001\u53ef\u5909\u9577\u306e\u30bf\u30d7\u30eb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"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":[14,89],"class_list":{"0":"post-418","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python","7":"category-it-programming","8":"tag-python","9":"tag-variable","10":"entry"},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"home-middle":false,"home-top":false,"sidebar-thumbnail":false},"uagb_author_info":{"display_name":"9nmatsumoto","author_link":"https:\/\/www.nblog09.com\/w\/author\/9nmatsumoto\/"},"uagb_comment_info":0,"uagb_excerpt":"Python\u306e\u95a2\u6570\u3067\u306e\u53ef\u5909\u9577\u5f15\u6570\u306e\u4f7f\u3044\u65b9 python\u3067\u306e\u53ef\u5909\u9577\u5f15\u6570\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b*\u3068**\u3092\u5f15\u6570\u306b\u4ed8\u4e0e\u3057\u3066\u4f7f&hellip;","_links":{"self":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/418","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=418"}],"version-history":[{"count":18,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/418\/revisions"}],"predecessor-version":[{"id":2806,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/posts\/418\/revisions\/2806"}],"wp:attachment":[{"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/media?parent=418"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/categories?post=418"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nblog09.com\/w\/wp-json\/wp\/v2\/tags?post=418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}