You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法在stop_word列表中更新单引号与双引号的技术求助

如何在stop_words列表中添加单引号和双引号?

我尝试在我的stop_word列表中更新单引号(')和双引号(")。

我运行了以下代码:

stop_words.update(["'", """ ])
stop_words

遇到了如下错误:

File "<ipython-input-85-54a2b8b08201>", line 2
stop_words


SyntaxError: EOF while scanning triple-quoted string literal--

问题原因

你误写了三个双引号""",Python会将其识别为三引号字符串的起始标记,但没有补充对应的结尾标记,因此触发语法错误。

正确写法

有三种简单的方式可以实现需求:

  • 方式1:交叉使用引号包裹目标字符
    用单引号包裹单引号,双引号包裹双引号:

    stop_words.update(["'", '"'])
    
  • 方式2:使用转义字符
    对引号前加反斜杠\进行转义:

    stop_words.update(['\'', '\"'])
    
  • 方式3:分开定义字符串
    用不同的引号分别定义两个目标字符:

    stop_words.update([ "'", '"' ])
    

内容的提问来源于stack exchange,提问作者Pauline21

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 15:25:25