不明白为什么我的函数没有被调用

Don't understand why my function is not being called

print ("Hello, User :)")
def search():
    answer = phrase.find(search)
    return answer

y = "Y"
while y == "Y":

    phrase = input("Please enter a phrase any phrase: ")
    print ("Thank you User - the phrase you entered reads as follows: ")
    print (phrase)

    search = input("Please enter one of the words of the phrase you just entered, or some consecutive characters from that phrase, and I will search for them: ")
    print ("Thank you, User")
    print ("Your word or characters are located at the following index location: ")
    search()
    #print (answer)

    y = input("Thanks for playing.  Would you like to play again(Y/N)?: ")
else:
    print ("Goodby, User")

希望有人能帮助解释为什么我的函数定义不能被调用。

函数名不能与变量名相同。只需像这样更改 search 变量名称:

search_ = input("Please enter one of the words of the phrase you just entered, or some consecutive characters from that phrase, and I will search for them: ")

search()

此外,如果您希望打印出结果,请像这样调用函数:

print(search())