Why is my conditional returning “none?”
本问题已经有最佳答案,请猛点这里访问。
每当我运行这个时,我会得到第三个选项,当它应该返回第一个选项时,因为s='是'。这里出什么事了?
| 1 2 3 4 5 6 7 8 9 10 11 | def shut_down(s): if s is 'yes': return 'Shutting down...' elif s is 'no': return 'Shutdown aborted!' else: return"Sorry, I didn't understand you" ans = 'Yes' s = ans.lower() shut_down(s) | 
变化
| 1 | if s is 'yes': | 
到
| 1 | if s == 'yes': | 
号
和
| 1 | elif s is 'no': | 
到
| 1 | elif s == 'no': | 
。
虽然