数字列表与字符串列表相互切换
- 数字列表切换为字符串列表
1.
1 ls = [1,2,3,4,5] 2 3 list1 = [str(x) for x in ls]
2.
1 list2 = list(map(str,ls))
- 字符串列表切换为数字列表
1.
1 list11 = [int(x) for x in list1]
2.
1 list22 = list(map(int,list2))
1.
1 ls = [1,2,3,4,5] 2 3 list1 = [str(x) for x in ls]
2.
1 list2 = list(map(str,ls))
1.
1 list11 = [int(x) for x in list1]
2.
1 list22 = list(map(int,list2))