定义可选函数参数的类型

问题描述 投票:0回答:1

在Python3中,我可以做:

# Function with string as input
def function(argument: str):
    return argument

但是我不能:

# Function with optional input
def function(argument='default': str):
    return argument

定义可选参数类型的正确语法是什么?

python syntax
1个回答
1
投票

只需交换默认值和类型的位置

© www.soinside.com 2019 - 2024. All rights reserved.