为什么这个字符串比较不起作用? (difflib)

时间:2017-11-28 18:27:43

标签: python-3.x if-statement difflib

此代码应该是打印"我是单位Alpha 07"当用户说出"你的名字是什么",但由于某种原因,if语句永远不会返回true。请帮忙!

import difflib
    while True:
     talk = input("Please say something > ")
     temp = (difflib.get_close_matches(talk, ['What is your name?', 'Hello', 'peach', 'puppy'],1,0.2))
     print(temp)
     if temp == "['What is your name?']":
      print("I am unit Alpha 07")
      break
     continue

    input()

Here's a screenshot

对不起,如果这真的很蠢。

1 个答案:

答案 0 :(得分:0)

由于var nodesMatching = from node in myXDocument.Descendants() where node.Name.LocalName.Equals("mySearchNode") select node; var node = nodesMatching.FirstOrDefault(); temp,并且您想检查list该列表的第一个ifelement,那么您不能像你所做的What is your name?一样string,你需要检查第一个元素(索引"['What is your name?']"),然后比较一下:

0

这将有效。祝你好运!