首页 > 解决方案 > 试图比较两个字符串。失败,因为字符串总是以 u"foobar" 开头

问题描述

我有两个清单

list1 = ["foo", "bar"]

list2 = ["foo", "bar"]

我有一个text_match比较两个字符串的方法:

def text_match(self, expected, actual):
    if expected == actual:
        return True
    else:
    return False

我调用方法

self.text_match(list1[0], list2[0])

我弄错了。

当我从列表中打印两个字符串时

list1[0]>> 富

list2[1]>> 你“富”

为什么打印时它们不一样?我试过编码、解码、转换为字符串。没有任何效果。

有任何想法吗?

标签: stringpython-2.7listcompare

解决方案


def text_match(self, expected, actual):
  if expected == actual:
      return True
  else:
      return False

这个错误永远不会让脚本有机会工作

Return Flase 不能与 else 在同一个缩进中:


推荐阅读