{"id":8142,"date":"2024-06-21T21:01:01","date_gmt":"2024-06-21T13:01:01","guid":{"rendered":""},"modified":"2024-06-21T21:01:01","modified_gmt":"2024-06-21T13:01:01","slug":"python\u5b66\u4e60\u57fa\u7840\u7bc7\u2014\u2014\u5b9e\u73b0 switch \u529f\u80fd","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8142.html","title":{"rendered":"python\u5b66\u4e60\u57fa\u7840\u7bc7\u2014\u2014\u5b9e\u73b0 switch \u529f\u80fd"},"content":{"rendered":"

python \u6846\u67b6\u4e2d\u5e76\u6ca1\u6709 switch \u8fd9\u4e2a\u51fd\u6570\uff0c\u4f46\u662f\u901a\u8fc7\u5b57\u5178\u548c\u51fd\u6570\u76f8\u7ed3\u5408\u7684\u5f62\u5f0f\u5b9e\u73b0 Switch \u7684\u529f\u80fd\uff0c\u4e0b\u9762\u4ee3\u7801\uff1a\u7b80\u5355\u51fd\u6570\u5b9e\u73b0\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\uff0c\u5176\u4e2dlambda \u533f\u540d\u51fd\u6570\u7684\u4f7f\u7528 \uff0c\u6ca1\u6709\u7528\u592a\u591a\uff0c\u8fd8\u671b\u770b\u5230\u7684\u6307\u6b63\u3002<\/p>\n

#coding:utf-8 # from __future__ import division python 2 \u9700\u8981\u5f15\u5165\u6b64\u6a21\u5757\uff0c\u4e0d\u71365\/2=2\u5f15\u5165\u540e=2.5 python3 \u4e2d\u65e0# \u9700\u5f15\u5165 5\/2=2.5 5\/\/2=2 def add(x,y): return x+y def subtract(x,y): return x-y def multiply(x,y): return x*y def divide(x,y): return x\/y def operator(x,o,y): if o == \"+\" : print(add(x,y)) elif o == \"-\" : print(subtract(x,y)) elif o == \"*\" : print(multiply(x,y)) elif o == \"\/\" : print(divide(x,y)) else: pass operator(2,\"\/\",6) # \u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 \u4fee\u6539\u6210switch\u5f62\u5f0f \u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026\u2026 # \u901a\u8fc7\u5b57\u5178\u548c\u51fd\u6570\u7684\u7ed3\u5408\u5b9e\u73b0switch\u51fd\u6570\u529f\u80fd\u3002 op = {\"+\": add, \"-\" :subtract ,\"*\": multiply,\"\/\": divide} print(add) print(op[\"+\"]) # \u901a\u8fc7\u5b57\u5178\u5b9e\u73b0\u51fd\u6570\u7684\u8c03\u7528 \u6548\u679c\u548c print(add)\u76f8\u540c print(add(<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"python\u5b66\u4e60\u57fa\u7840\u7bc7\u2014\u2014\u5b9e\u73b0 switch \u529f\u80fdpython\u6846\u67b6\u4e2d\u5e76\u6ca1\u6709switch\u8fd9\u4e2a\u51fd\u6570\uff0c\u4f46\u662f\u901a\u8fc7\u5b57\u5178\u548c\u51fd\u6570\u76f8\u7ed3\u5408\u7684\u5f62\u5f0f\u5b9e\u73b0Switch\u7684\u529f\u80fd\uff0c...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8142"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=8142"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8142\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}