【问题标题】:Can I define both function's argument's default value and data type in python? [duplicate]我可以在 python 中定义函数参数默认值和数据类型吗? [复制]
【发布时间】:2020-09-05 15:35:15
【问题描述】:

我想写这样的东西。

1) def func_name(arg1, arg2, arg3 = 3) #这定义了可选参数arg3的默认值

2) def func_name(arg1, arg2, arg3: int) #这定义了所需参数arg3的数据类型

是否有任何可能的方法来定义它们? 像这样的

def func_name(arg1, arg2, arg3 = 3: int)

【问题讨论】:

标签: python function arguments type-hinting optional-arguments


【解决方案1】:

你可以这样使用。

def boo(arg1, arg2, arg3:int = 10):
    ....

更多信息在这里。

https://www.python.org/dev/peps/pep-0484/#arbitrary-argument-lists-and-default-argument-values

【讨论】:

    猜你喜欢
    • 2011-06-02
    • 1970-01-01
    • 2011-04-18
    • 2014-04-28
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多