Python 连接字符串(join %)
更新时间:2008年09月06日 13:28:00 作者:
join 方法用于连接字符串数组,使用 % 连接多个变量下面看例子
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
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']
相关文章
PyCharm 2021.2 (Professional)调试远程服务器程序的操作技巧
本文给大家分享用 PyCharm 2021 调试远程服务器程序的过程,通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧2021-08-08python socket 超时设置 errno 10054
这篇文章主要介绍了python 远程主机强迫关闭了一个现有的连接 socket 超时设置 errno 10054 ,需要的朋友可以参考下2014-07-07解决使用Spyder IDE时matplotlib绘图的显示问题
这篇文章主要介绍了解决使用Spyder IDE时matplotlib绘图的显示问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2021-04-04
最新评论