import functools @functools.singledispatch def show(text): pass @show.register(str) def _(text): print(type(text)) @show.register(int) def _(text): print(type(text))
python通过functools.singledispath装饰器实现类似重载的功能
最新推荐文章于 2024-05-11 10:02:17 发布
import functools @functools.singledispatch def show(text): pass @show.register(str) def _(text): print(type(text)) @show.register(int) def _(text): print(type(text))

被折叠的 条评论
为什么被折叠?