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

Python中如何移除输出列表元素外侧的单引号?

原因说明

你观察到的单引号并不是列表元素本身的内容,是Python在打印字符串类型的列表元素时,默认添加的标识,用于区分字符串类型和其他类型的元素,实际存储在列表里的元素是不带单引号的。你可以通过打印单个元素验证:

msg1 = "  Facebook already uses AI to Filter Fake stories from the feeds of users"
words = msg1.split()
print(words[0])
# 输出结果为:Facebook,无单引号

格式化输出方案

如果需要得到你要求的展示格式,手动拼接输出字符串即可,参考代码如下:

msg1 = "  Facebook already uses AI to Filter Fake stories from the feeds of users"
words = msg1.split()
# 按期望格式拼接字符串
format_output = "[" + words[0] + " , " + ", ".join(words[1:]) + "]"
print(format_output)

运行后输出完全匹配你的预期:
[Facebook , already, uses, AI, to, Filter, Fake, stories, from, the, feeds, of, users]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 00:06:04