jakeyfly
V2EX  ›  问与答

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

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

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

    比如值是 1,或 2 这样

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