nosilence 发表于 2015-4-22 06:45:55

Python天天美味(7)

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']
  
Python天天美味系列(总)
Python    天天美味(5) - ljust rjust center     Python    天天美味(6) - strip lstrip rstrip
  Python    天天美味(7) - 连接字符串(join %)
  Python    天天美味(8) - 字符串中的字符倒转
  Python    天天美味(9) - translator
  ...
页: [1]
查看完整版本: Python天天美味(7)