Adding default parameter value with type hint in Python

后端 未结 3 480
执笔经年
执笔经年 2020-11-28 19:37

If I have a function like this:

def foo(name, opts={}):
  pass

And I want to add type hints to the parameters, how do I do it? The way I as

3条回答
  •  伪装坚强ぢ
    2020-11-28 20:26

    I recently saw this one-liner:

    def foo(name: str, opts: dict=None) -> str:
        opts = {} if not opts else opts
        pass
    

提交回复
热议问题