[Python] 实现tuple和list的转换

1.list列表转换为tuple元组

temp_list = [1,2,3,4,5]
print(temp_list)  # [1, 2, 3, 4, 5]
print(type(temp_list))  # 
# 将temp_list进行强制转换
a = tuple(temp_list)    
print(a)  # (1, 2, 3, 4, 5)
print(type(a))  # 

2.tuple元组转换为list列表

temp_tuple = (1,2,3,4)
print(temp_tuple)  # (1, 2, 3, 4)
print(type(temp_tuple))  # 
# 将temp_tuple进行强制转换
b = list(temp_tuple)    
print(b)  # [1, 2, 3, 4]
print(type(b))  # 

你可能感兴趣的:(Python,python,开发语言)