python列表(list)、元祖(tuple)、集合(set),和字典(dictionary)的比较

xiaoxiao2021-02-28  34

数据类型列表(list)元祖(tuple)集合(set)字典(dictionary)定义a_list = [1, True, ‘aa’]a_tuple = (1, True, ‘aa’)a_set = {1, True, ‘aa’}a_dict = {‘name’: ‘pirlo’, ‘age’: 21}是否有序有序有序无序无序空定义a_list = []a_tuple = ()a_set = set(),not_sure = {}创建的是空字典a_dict = {}元素可修改a_list[0] = 23否否a_dict[‘age’] = 30下标访问a_list[0] = 23a_tuple[0]否a_dict[‘age’] = 30添加元素+、append、extend、insert不可添加add、updatea_dict[‘new_key’] = ‘value’删除元素del、remove、pop()、pop(1)、clear不可删除discard、remove、pop、clearpop、popitem、clear元素查找index、count、ininina_dict[‘key’]布尔真值非空非空非空非空
转载请注明原文地址: https://www.6miu.com/read-2150235.html

最新回复(0)