V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
jakeyfly
V2EX  ›  问与答

Python 中的单分派函数 是根据传入参数的类型来执行不同的操作,那可以根据值吗

  •  
  •   jakeyfly · Jul 9, 2019 · 1504 views
    This topic created in 2484 days ago, the information mentioned may be changed or developed.

    就是根据值,来分派。有可能实现吗

    比如值是 1,或 2 这样

    4 replies    2019-07-09 12:06:39 +08:00
    leishi1313
        1
    leishi1313  
       Jul 9, 2019 via Android
    princelai
        2
    princelai  
       Jul 9, 2019
    好像没有这样的装饰器或方法吧,自己写个函数,内部 if else 判断下?
    jakeyfly
        3
    jakeyfly  
    OP
       Jul 9, 2019
    @princelai 就是不想用 IF ELSE 的方式 想通过分派的来弄
    goofool
        4
    goofool  
       Jul 9, 2019
    定义自己的 int 类
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1802 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 16:24 · PVG 00:24 · LAX 09:24 · JFK 12:24
    ♥ Do have faith in what you're doing.