string - 试图比较两个字符串。失败,因为字符串总是以 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]
>> 你“富”
为什么打印时它们不一样?我试过编码、解码、转换为字符串。没有任何效果。
有任何想法吗?
解决方案
def text_match(self, expected, actual):
if expected == actual:
return True
else:
return False
这个错误永远不会让脚本有机会工作
Return Flase 不能与 else 在同一个缩进中:
推荐阅读
- c# - 创建 C# 模型以反序列化 XML 提要
- javascript - js-graph.it:如何动态添加块并使用连接器建立连接
- azure-data-factory - 是否可以参数化 Azure 数据工厂查找的源数据集的选择?
- elasticsearch - 如何在弹性搜索中使用范围聚合和过滤查询
- javascript - 如何预加载尚未在 NextJs 中渲染的图像
- amazon-web-services - 如何通过 AMI 使 EBS 卷可安装在硝基和普通实例上
- angular - Angular 13 多入口点代码覆盖率
- c# - 无法从给定的 mod 和 exp 生成公钥。抛出“坏数据”
- visual-studio - Visual Studio 2019 - 快速查找?(CTRL-T) 像 reshaper
- android - 在哪里放置 Android 应用程序所需的 ONNX 运算符