-4

我一直在调试这段代码,无法让==操作员处理两个匹配的字符串。

编码:

str1 = "string1"
str2 = "string2"

print str1
print str2

for row in results:
  print row[0]
  print row[1]   #as requested
  if((row[0] == str1) and (row[1] == str2)):
     print "We found the match....."
     #rest of the code
4

1 回答 1

2

确保用 . 清除空格.strip()

>>> str1 = "string1"
>>> str2 = "string2"
>>>
>>> results = [["string1 ", " string2"]]
>>> for row in results:
...   if((row[0].strip() == str1) and (row[1].strip() == str2)):
...      print "We found the match....."
...
We found the match.....
>>>
于 2012-10-03T01:57:58.963 回答