[英]How do you use a function as a parameter in a function?
我试图将一个函数用作另一个函数中的参数,但我不断收到错误消息。 你们能看看我的代码吗?
#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())
我不知道您要得到错误,但我看到错误:
您必须将remove(sentence)
结果分配给变量,并在convertList()
使用此结果
result = remove(sentence)
convertList(result)
或者您必须直接在convertList()
函数与参数remove(sentence)
一起使用
convertList(remove(sentence))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.