元组tuple 可迭代对象

1. 字符串、元组和列表相互转化

s = 'abcdef'
li = ['a','b','c','d']
tu = (1,2,4,9)
v = tuple(s)
print('v = ',v)
w = list(s)
print('w =',w)
m = list(tu)
print('m =',m) ————————————————
v = ('a', 'b', 'c', 'd', 'e', 'f')
w = ['a', 'b', 'c', 'd', 'e', 'f']
m = [1, 2, 4, 9]

2. extend()

li = ['a','bcd']
li.extend((11,22,33))
print(li) ['a', 'bcd', 11, 22, 33]

  

3.如果元素中只有字符串,可以拼接转换u = ''.join(li)

print('u =',u)
u = abcd
上一篇:vim - 自动补齐


下一篇:20165305 实验二:Java面向对象程序设计