【问题标题】:Are there different ways to print a list in python? [duplicate]在 python 中打印列表有不同的方法吗? [复制]
【发布时间】:2021-01-14 06:15:52
【问题描述】:

我是 python 新手。还有其他打印列表的方法吗

li1 = ['This is one sentence. ' 'This is another.']
print(...)

然后输出将是:

This is one sentence. This is another.

【问题讨论】:

  • 什么是...?如果是li1,那就换成li1
  • 这能回答你的问题吗? Pythonic way to print list items
  • 这个列表只有一个字符串。你确定这就是你想要的吗?

标签: python python-3.x list


【解决方案1】:

你可以解压列表

print(*l)

并选择元素之间的分隔符。

print(*l, sep=', ')

【讨论】:

  • 甚至sep=''
【解决方案2】:

或尝试类似print(''.join(li1))

【讨论】:

    猜你喜欢
    • 2020-08-22
    • 1970-01-01
    • 2010-11-12
    • 2021-02-20
    • 1970-01-01
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多