元祖跟列表之间的转化:

tu = (1, 2, 3)
l = list(tu)
print(l, type(l))

li = [4, 5, 6]
print(tuple(li),type(tuple(li)))

输出:
[1, 2, 3] <class 'list'>
(4, 5, 6) <class 'tuple'>


字符串转化成列表:

split:

s = "ab_c"
lst = s.split("_")
print(lst)

输出:
['ab', 'c']

 

或者:

s = "ab_c"
print(list(s))

输出:
['a', 'b', '_', 'c']

 

列表转化成字符串:

join

lst = ["a", "b", "c", "d"]
s = "*".join(lst)
print(s)

输出:
a*b*c*d

或者:

lst = ["a", "b", "c", "d"]
s = str(lst)
print(s,type(s))

输出:
['a', 'b', 'c', 'd'] <class 'str'>

 

字符串转化成元祖:

s = "ab_c"
t = tuple(s)
print(t, type(t))

输出:
('a', 'b', '_', 'c') <class 'tuple'>

 

1, int ------> str:    str(int)

2, str------->int:     int(str) #字符串必须全部由数字组成

3,bool ------->str:    str(bool)

4,str -------->bool  除了空字符串,剩下的都是True

5,int -------->bool 除了0,剩下的全是True

6,bool ------->int  True----->1,False ----->0

7,str --------> list     #split

8,list -------->str     #join

9,tuple-------->list:    list(tuple)

10,list --------->tuple:  tuple(list)

11,str ------>list:    list(str)

12,str ------>tuple  tuple(str)