[英]Function that takes in optional parameter
From the below code after submitting it as a coding test challenge.在将其作为编码测试挑战提交后,来自以下代码。 I used to get the following feedback from a robot or a bot that is marking the challenge that task() missing 1 required positional argument: 'name' but if I do run it on vs code it will print Hello Friend.
我曾经从机器人或机器人那里得到以下反馈,这些反馈标志着 task() 缺少 1 个必需的位置参数的挑战:'name' 但如果我在 vs code 上运行它,它将打印 Hello Friend。 And I don't know why.
我不知道为什么。 Please Clarify.
请澄清。
def task(name):
print("Hello", name + "!")
task("Friend")
Maybe they test task()
without an argument for name
.也许他们在没有参数
name
的情况下测试task()
。 Try to set a default value like this尝试像这样设置默认值
def task(name=""):
print("Hello", name + "!")
task("Friend") # Hello Friend!
task() # Hello !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.