天天看點

Python天天美味(7) - 連接配接字元串(join %)

Python天天美味(7) - 連接配接字元串(join %)

s = ['a', 'b', 'c', 'd']

Python天天美味(7) - 連接配接字元串(join %)

print ''.join(s)

Python天天美味(7) - 連接配接字元串(join %)

print '-'.join(s)

輸出結果:

abcd

a-b-c-d

Python天天美味(7) - 連接配接字元串(join %)

a = 'hello'

Python天天美味(7) - 連接配接字元串(join %)

b = 'python'

Python天天美味(7) - 連接配接字元串(join %)

c = 1

Python天天美味(7) - 連接配接字元串(join %)

print '%s %s %s %s' % (a, b, c, s)

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

<a target="_blank" href="http://www.cnblogs.com/coderzh/archive/2008/05/03/1180584.html">Python 天天美味(8) - 字元串中的字元倒轉</a>

<a target="_blank" href="http://www.cnblogs.com/coderzh/archive/2008/05/03/1180705.html">Python 天天美味(9) - translator</a>

... 

本文轉自CoderZh部落格園部落格,原文連結:http://www.cnblogs.com/coderzh/archive/2008/05/03/1180563.html,如需轉載請自行聯系原作者