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

posted on 2019-01-30 16:50  大叔学AI  阅读(957)  评论(0编辑  收藏  举报