如何在Python中打印带有字符串的列表?

2024-09-27 18:10:44 发布

您现在位置:Python中文网/ 问答频道 /正文

除了一些文字外,我正在打印我最喜欢的游戏的列表。你知道吗

代码:

favGames = ["The Division", "WoW", "Legend of Zelda", "Super Smash Bros."]

print("Here are some of my favorite games! " + favGames)

期望值: 我只想得到一行:

Here are some of my favorite games! The Division, WoW, Legend of Zelda, Super Smash Bros.

我收到以下错误消息: TypeError:只能将list(而不是“str”)连接到list


Tags: oftheheremysomearefavoritedivision
1条回答
网友
1楼 · 发布于 2024-09-27 18:10:44

尝试使用str.join,并通过命令和空格连接它:

print("Here are some of my favorite games! " + ', '.join(favGames))

输出:

Here are some of my favorite games! The Division, WoW, Legend of Zelda, Super Smash Bros.

相关问题 更多 >

    热门问题