为什么 Python 代码在没有双重打印请求时返回 'None'?

Why is Python code returning 'None' when there is no double print requests?

这是我在 main() 中的程序的开头。第一个输入请求是在 space 中打印 'None' ,用户应该在其中键入他们的输入。用户仍然可以输入,但我无法摆脱 'None'。

我试过修改 return 语句位于 while 语句末尾的位置,这不会影响任何东西(现在它刚刚被删除,但即使它是仍然包含它 returns None)。我不是要它打印两次(据我所知)。

while True:
    start = input(str(print('Would you like to find out your USA weather forecast? Please enter YES or NO.\n')))
    if start.upper() == 'YES':
        choice()
    elif start.upper() == 'NO':
        print('*'*31)
        print('Thank you for joining us today!')
        print('*'*31)
        exit(0)
    else:
        print('Please enter a valid response.')
        break

你想要:

start = input('Would you like to find out your USA weather forecast? Please enter YES or NO.\n')

发生了什么:

要查看您的代码中发生了什么,请从最内层的函数调用 (print) 到最外层的 (input) 阅读它。 print 函数调用通常会在屏幕上打印一些内容,但它不会 return 一个值,因此它的默认 return 是 None。然后,您对该 return 值调用 strstr(None) 是 "None"。然后将该值传递给 input,即 input("None")。这就是在您的提示符下显示的内容。