{"id":5742,"date":"2022-08-12T11:14:39","date_gmt":"2022-08-12T03:14:39","guid":{"rendered":"http:\/\/139.9.1.231\/?p=5742"},"modified":"2022-08-12T11:14:40","modified_gmt":"2022-08-12T03:14:40","slug":"argskwargs","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/08\/12\/argskwargs\/","title":{"rendered":"python\u51fd\u6570\u4e2d*args \u548c**kwargs\u7684\u7528\u6cd5"},"content":{"rendered":"\n<p class=\"has-light-pink-background-color has-background\"><strong>\u51fd\u6570\u7684\u53c2\u6570\u6570\u91cf\u4e0d\u786e\u5b9a\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528*args \u548c**kwargs\uff0c*args \u6ca1\u6709key\u503c\uff0c**kwargs\u6709key\u503c\u3002<\/strong><\/p>\n\n\n\n<p>\u8fd9\u6837\u8bf4\u5427\uff1a\u8fd9\u4e2a\u662fPython\u51fd\u6570\u53ef\u53d8\u53c2\u6570args\u53cakwargs *<strong>args\u8868\u793a\u4efb\u4f55\u591a\u4e2a\u65e0\u540d\u53c2\u6570\uff0c\u5b83\u662f\u4e00\u4e2atuple<\/strong>    **<strong>kwargs\u8868\u793a\u5173\u952e\u5b57\u53c2\u6570\uff0c\u5b83\u662f\u4e00\u4e2adict<\/strong><\/p>\n\n\n\n<h1>\u793a\u4f8b:<\/h1>\n\n\n\n<p>def highschool_class(number,*args):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> print(\"the highschool_class  has %s \"%number)  #\u9ad8\u4e2d\u4e00\u4e2a\u73ed\u7ea7\u7684\u4eba\u6570    \n print(*args)    \n return (args)  <\/code><\/pre>\n\n\n\n<p>highschool_class(59,30,29)<\/p>\n\n\n\n<p>\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>the highschool_class has 59<br>30 29<\/p>\n\n\n\n<p>Process finished with exit code 0<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>def highschool_class(number,*<em>args,**kwargs): print(&#8220;the highschool_class has %s &#8220;%number) #\u9ad8\u4e2d\u4e00\u4e2a\u73ed\u7ea7\u7684\u4eba\u6570 print(<\/em>args)<br>print(kwargs)<br>return (args,kwargs)<\/p>\n\n\n\n<p>highschool_class(59,30,29,male = &#8217;30&#8217;,female = &#8217;29&#8217;)<\/p>\n\n\n\n<p>\u7ed3\u679c\uff1a<\/p>\n\n\n\n<p>the highschool_class has 59<br>30 29<br>{&#8216;male&#8217;: &#8217;30&#8217;, &#8216;female&#8217;: &#8217;29&#8217;}<\/p>\n\n\n\n<p>Process finished with exit code 0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u51fd\u6570\u7684\u53c2\u6570\u6570\u91cf\u4e0d\u786e\u5b9a\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528*args \u548c**kwargs\uff0c*args \u6ca1\u6709key\u503c\uff0c**kwargs\u6709k &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/08\/12\/argskwargs\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">python\u51fd\u6570\u4e2d*args \u548c**kwargs\u7684\u7528\u6cd5<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5742"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=5742"}],"version-history":[{"count":5,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5742\/revisions"}],"predecessor-version":[{"id":5747,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/5742\/revisions\/5747"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=5742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=5742"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=5742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}