Python 连接字符串(join %)
更新时间:2008年09月06日 13:28:00 作者:
join 方法用于连接字符串数组,使用 % 连接多个变量下面看例子
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语言检测模块langid和langdetect的使用实例
今天小编就为大家分享一篇关于Python语言检测模块langid和langdetect的使用实例,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧2019-02-02
Python操作MySQL数据库的两种方式实例分析【pymysql和pandas】
这篇文章主要介绍了Python操作MySQL数据库的两种方式,结合实例形式分析了Python使用pymysql和pandas模块进行mysql数据库的连接、增删改查等操作相关实现技巧,需要的朋友可以参考下2019-03-03


最新评论