为什么此函数返回LinkedIn而不是Amazon?

时间:2020-07-12 21:06:47

标签: python function local

为什么此函数返回LinkedIn而不是Amazon?

def hey(location):
        location = "LinkedIn"
        answer = "Welcome to " + location
        return answer
        
print(hey("Amazon"))

1 个答案:

答案 0 :(得分:0)

因为您在函数内部将location声明为"LinkedIn"

如果没有为"LinkedIn"输入任何参数,如果您希望location为默认值,请尝试:

def hey(location="LinkedIn"):
    return "Welcome to " + location