python 怎么把列表的[]去掉?下面给大家讲解具体方法:
LIST = ['Python','problem','whatever'] print(LIST)
运行结果:
[Python, problem, whatever]
相关推荐:《Python视频教程》
如果想从输出中删除方括号可以将其转换为字符串,而不是直接打印列表:
>>> LIST = ['Python','php','java'] >>> print(", ".join(LIST)) Python, php, java
如果列表中的元素不是字符串,您可以使用repr(如果您想要引用字符串)或str(如果没有)将它们转换为字符串,如下所示:
>>> LIST = [1, "foo", 3.5, { "hello": "bye" }] >>> print(", ".join(repr(e) for e in LIST)) 1, 'foo', 3.5, {'hello': 'bye'}
以上就是python 怎么把列表的[]去掉的详细内容,更多请关注php中文网其它相关文章!
声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论