我有一个文本字符串-“该类还包含一个字符串,用于表示集合的标题和标量布尔变量,指示该集合当前是否可编辑。”
在这里,我试图获取子字符串“ collection's”的索引,但出现以下错误。 ValueError:找不到子字符串
我知道实际文本中子字符串中的撇号使用不同的字体。因此,有什么方法可以绕过字体的差异。
txt = "The class also contains a string for the collection’s title and a scalar Boolean variable indicating whether the collection is currently editable."
print(txt.index("collection's"))
期望具有子字符串“集合的”的索引
实际结果是:ValueError:找不到子字符串enter code here
答案 0 :(得分:4)
这是因为’
和'
是不同的字符
答案 1 :(得分:0)
只需确保您要查找的文本和字符串使用相同形式的撇号pulumi stack
'