python - 如何将列表转换为多行字符串?

标签 python

我有以下列表:

["Jargon", "Hello", "This", "Is", "Great"]

我想用以下内容填充一个字符串:

"""
{}
""".format(list-elements-besides-the-first)

有没有一种简单的衬垫可以用来制作它,这样我就可以:

  1. 获取数组的所有元素(第一个元素除外)并将其放入 {}?
  2. 是否可以让每个元素都显示在自己的行中?

最佳答案

"""
{}
""".format("\n".join(items[1:]))

关于python - 如何将列表转换为多行字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28572074/

相关文章:

python - 自定义命名实体识别

python - 为什么来自字典的数据帧在 R 中的行为与通过网状结构的独立数据帧不同?

python - 通过自己的分类器使用 tensorflow 进行对象检测

python - 将 python 脚本编译为独立程序

python - Python 中的战舰

python - 交换功能输出与预期不同

python - 用 C 编写的 Python 模块中的常量整数属性

python - 对称矩阵及其转置的逻辑比较

python - IO错误: codec configuration error when reading image file

python - 使用 pywinauto 时出错