教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 python怎么去掉数据的方括号

python怎么去掉数据的方括号

发布时间:2020-10-28   编辑:jiaochengji.com
教程集为您提供python怎么去掉数据的方括号等资源,欢迎您收藏本站,我们将为您提供最新的python怎么去掉数据的方括号资源
平时python输出list字符串时,会自动加上引号和中括号。

比如(推荐学习:Python视频教程)

str=['hello','world']
>>> str
['hello', 'world']

方法1

可以用join方法:

>>> 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怎么去掉数据的方括号的详细内容,更多请关注教程集其它相关文章!

  • 本文原创发布教程集,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    python怎么去掉数据的方括号
    Python怎么表示一个列表
    python input函数如何不要引号
    python怎么算两个数减法
    python怎么创建字符串变量
    asp后段如何调用python
    python中的list是什么
    python怎么取消注释
    Python列表怎么更新值?
    详解Python中的缩进和选择

    [关闭]
    ~ ~