编写一个名为 introduction(name, school) 的函数,它将名称(作为字符串)和学校作为输入,并返回以下文本:“Hello.我的名字是名字。我一直想上学。”
这是我的代码
def introduction("name","school"):
return ("Hello. My name is ") + str(name) + (". I have always wanted to go to The") + str(school) + (".")
我收到这个错误:
Traceback (most recent call last):
File "None", line 5, in <module>
invalid syntax: None, line 5, pos 23
最佳答案
def introduction("name","school"):
应该是
def introduction(name,school):
您提供的作为函数形式参数的名称本质上是实际参数值被分配给的变量。包括文字值(如字符串)没有多大意义。
当您调用或调用该函数时,就是您提供真实值(如文字字符串)的地方
def introduction(name,school):
return ("Hello. My name is ") + str(name) + (". I have always wanted to go to The") + str(school) + (".")
print introduction("Brian","MIT")
关于python - 基本的字符串和变量python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18601319/