# 列表list 有序集合 索引操作 可变的序列
# 元组tuple 有序集合 索引操作 不可变的序列
# 和list相比
# 1.比列表操作速度快
# 2.对数据“写保护“
# 3.可用于字符串格式化中
# 4.可作为字典的key
# 字典dict 无序集合 key操作 可变映射类型,哈希应用
# 和list比较,dict有以下几个特点:
# 1.查找和插入的速度极快,不会随着key的增加而增加
# 2.需要占用大量的内存,内存浪费多
# 而list相反:
# 1.查找和插入的时间随着元素的增加而增加
# 2.占用空间小,浪费内存很少
示例代码:
str1 = "czjmdnes"
test_1 = (1, 2, 3, 4, 5, 6)
test_2 = [1, 2, 3, 4, 5, 6, 7]
test_3 = {"name": "czj", "age":23, "height": 173}
print(type(str1))
print(type(test_1))
print(type(test_2))
# 元组 to 列表
test_1_tolist = list(test_1)
# 列表 to 元组
test_2_totuple = tuple(test_2)
# 字符串 to 列表
str1_tolist = list(str1)
print(type(test_1_tolist))
print(type(test_2_totuple))
print(type(str1_tolist))
运行结果:
<type 'str'>
<type 'tuple'>
<type 'list'>
<type 'list'>
<type 'tuple'>
<type 'list'>