python - 为什么这个函数返回 LinkedIn 而不是 Amazon?
问题描述
为什么这个函数返回 LinkedIn 而不是 Amazon?
def hey(location):
location = "LinkedIn"
answer = "Welcome to " + location
return answer
print(hey("Amazon"))
解决方案
location
因为您在"LinkedIn"
函数内部声明。
如果您希望"LinkedIn"
在没有参数输入的情况下作为默认值location
,请尝试:
def hey(location="LinkedIn"):
return "Welcome to " + location
推荐阅读
- prolog - 将列表从 findall 谓词转换为字符串序言
- c++ - 当文件通过 SMTP 发送时,它会丢失一些字节。C++
- elasticsearch - 有什么方法可以限制弹性搜索只匹配最接近的令牌?[边缘 n-gram,模糊性]
- amazon-web-services - AWS Kinesis SQL 的问题 - 随机森林砍伐算法
- python - 获取excel链接数据到python
- python - 我的 WordCloud 缺少单词末尾的字母 's'
- swift - 如何使用 DataRequest 在 alamofire 中设置超时
- ruby - 如何计算迭代/步骤的数量以找到方法的答案 - RUBY
- pandas - 获取每组变量分位数的值
- python - Plotly 图在 HTML 页面中显示为空白