描述:
用於把字符串用指定的符號鏈接起來,返回字符串格式
語法:
S.join(iterable)
- 1
S:需要的分隔符
iterable:被分割對象
(按語法字面理解s和iterable作用正好和實際交換)
實例:
對列表:
a = ['a','b','c','d','e']
print '-'.join(a)
print '*'.join(a[1:3])
輸出:
a-b-c-d-e
b*c
- 1
- 2
- 3
- 4
- 5
- 6
- 7
對元組:
b = ('q','w')
print '+'.join(b)
輸出:
q+w
- 1
- 2
- 3
- 4
- 5
對字符串:
c = 'hello'
print '*'.join(c[::-1])
輸出:
o*l*l*e*h
- 1
- 2
- 3
- 4
- 5
對字典:
d = {"a":a,"b":2}
print '-'.join(d)
輸出:
a-b