Skip to main content
 首页 » 编程设计

python之将列表拆分为字符串

2025年05月04日11thcjp

这是我的 list :

animals = ['dog', 'cat', 'mouse'] 

我想拆分它,所以我最终得到一个包含列表中的三个字符串的字符串,如下所示:

dog/cat/mouse 

我试过使用下面的代码,但它只打印原始列表:

print [e.split('/')[0] for e in animals] 

有什么问题吗?

请您参考如下方法:

你不想 split 你想加入,不知何故相反的操作。

animals = ['dog', 'cat', 'mouse'] 
"/".join(animals)