Python 连接字符串(join %)

上一篇 / 下一篇  2013-12-06 09:36:50

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'] 

TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-24  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 42878
  • 日志数: 22
  • 建立时间: 2013-05-29
  • 更新时间: 2013-12-28

RSS订阅

Open Toolbar