平时python输出list字符串时,会自动加上引号和中括号。
比如(推荐学习:Python视频教程)
str=['hello','world'] >>> str ['hello', 'world']
方法1
可以用join方法:
立即学习“Python免费学习笔记(深入)”;
>>> print " ".join(str) hello world
其中:Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。
比如:
str = "-" seq = ("a", "b", "c") print str.join( seq )
输出结果:
a-b-c
方法2:如果list存放的是数字,则:将其转为int即可。因为原来存放的是string型的
str=['1', '2', '3'] for i in str: int(i) print(i)
更多Python相关技术文章,请访问Python教程栏目进行学习!
以上就是python怎么去掉数据的方括号的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号