join 方法用于连接字符串数组
复制代码 代码如下:
s = ['a', 'b', 'c', 'd']
print ''.join(s)
print '-'.join(s)
输出结果:
abcd
a-b-c-d
使用 % 连接多个变量
复制代码 代码如下:
a = 'hello'
b = 'python'
c = 1
print '%s %s %s %s' % (a, b, c, s)
输出结果:
hello python 1 ['a', 'b', 'c', 'd']
复制代码 代码如下:
s = ['a', 'b', 'c', 'd']
print ''.join(s)
print '-'.join(s)
输出结果:
abcd
a-b-c-d
使用 % 连接多个变量
复制代码 代码如下:
a = 'hello'
b = 'python'
c = 1
print '%s %s %s %s' % (a, b, c, s)
输出结果:
hello python 1 ['a', 'b', 'c', 'd']
标签:
Python,连接字符串
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
内蒙古资源网 Copyright www.nmgbbs.com
暂无“Python 连接字符串(join %)”评论...