如果没有指定参数,如何向将要使用的函数添加值?
How to add values to function that will be used in case there is no argument specified?
所以,基本上我需要制作一个函数,将 2 个整数加在一起,return 它们的总和(a 和 b)。问题是,如果未指定 a 或 b,函数将默认使用 a = 0 和 b = 1,如果没有参数,我如何让函数使用这些数字?
我觉得你可以写
def sum(a = 0, b = 1):
所以,基本上我需要制作一个函数,将 2 个整数加在一起,return 它们的总和(a 和 b)。问题是,如果未指定 a 或 b,函数将默认使用 a = 0 和 b = 1,如果没有参数,我如何让函数使用这些数字?
我觉得你可以写
def sum(a = 0, b = 1):