如何让这个 If 语句条件正常工作?

How do I get this If statement condition to work properly?

我在使用以下代码时遇到问题:

decision = str(input("Would you like to change it?:"))
if decision.lower == 'yes':
    new_holiday = input("What is your new favorite holiday?:")

问题在于,当我在第一个提示中输入 'yes' 时,它没有按我的意愿显示第二个提示,而是完全跳过了 if 语句。我在这里遗漏了什么吗?

decision.lower 生成方法 <built-in method lower of str object at ...>。你应该打电话给 decision.lower().

将您的代码更改为以下内容:

decision = str(input("Would you like to change it?:"))
if decision.lower() == 'yes':
    new_holiday = input("What is your new favorite holiday?:")

decision.lower() 使用此方法将 return 一个小写字符串。

decision = input("Would you like to change it?:")
if decision.lower() == 'yes':
    new_holiday = input("What is your new favorite holiday?:")