[英]How do you use a function as a parameter in a function?
I am trying to use a function as a parameter in another function but I keep getting an error. 我试图将一个函数用作另一个函数中的参数,但我不断收到错误消息。 Can you guys please take a look at my code.
你们能看看我的代码吗?
#Program used to reverse the order of a string.
sentence = input("Write a sentence. After you click enter it will be returned in reverse order. ")
userInputList = [ ]
reverseInputList = [ ]
#remove any periods from the sentence.
def remove(sentence):
stripped = sentence.replace(".", "")
return stripped
#print string in reverse order
def convertList(stripped):
userInputList = stripped.split()
reverseInputList = userInputList[::-1]
for i in range(len(reverseInputList)):
print (reverseInputList[i], end=" ")
remove(sentence)
convertList(remove())
I don't know want error you get but I see mistake: 我不知道您要得到错误,但我看到错误:
you have to assign result from remove(sentence)
to variable and use this result in convertList()
您必须将
remove(sentence)
结果分配给变量,并在convertList()
使用此结果
result = remove(sentence)
convertList(result)
or you have to use function with argument remove(sentence)
directly in convertList()
或者您必须直接在
convertList()
函数与参数remove(sentence)
一起使用
convertList(remove(sentence))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.