Python天天美味(7) - 连接字符串(join %)


join 方法用于连接字符串数组

= ['a''b''c''d']
print ''.join(s)
print '-'.join(s)

输出结果:
abcd
a-b-c-d

使用 % 连接多个变量

= 'hello'
= 'python'
= 1
print '%s %s %s %s' % (a, b, c, s)

输出结果:

hello python 1 ['a', 'b', 'c', 'd']


Python 天天美味系列(总)

Python 天天美味(5) - ljust rjust center  

Python 天天美味(6) - strip lstrip rstrip  

Python 天天美味(7) - 连接字符串(join %)  

Python 天天美味(8) - 字符串中的字符倒转

Python 天天美味(9) - translator

...

posted @ 2008-05-03 20:27  CoderZh  阅读(3885)  评论(3编辑  收藏  举报