分享

python 怎么把列表的[]去掉

 文炳春秋 2020-04-08

第85页-Python教程_Python图文教程-php中文网  https://www./python-tutorials.html?p=85

python 怎么把列表的[]去掉?下面给大家讲解具体方法:

1

2

LIST = ['Python','problem','whatever']

print(LIST)

运行结果:

1

[Python, problem, whatever]

相关推荐:《Python视频教程

如果想从输出中删除方括号可以将其转换为字符串,而不是直接打印列表:

1

2

3

>>> LIST = ['Python','php','java']

>>> print(", ".join(LIST))

Python, php, java

如果列表中的元素不是字符串,您可以使用repr(如果您想要引用字符串)或str(如果没有)将它们转换为字符串,如下所示:

1

2

3

>>> LIST = [1, "foo", 3.5, { "hello": "bye" }]

>>> print(", ".join(repr(e) for e in LIST))

1, 'foo', 3.5, {'hello': 'bye'}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多