我的疑惑:
什么是数据结构?python有哪些地方用到数据结构?
什么是数据结构?
数据结构:互相之间存在着一种或多种关系的数据元素的集合和该集合中数据元素之间的关系组成
数据可以比作是书本, 数据结构相当于书架,书存放在书架上,要拿书,我们就得到书架上面去取。为了更快的拿到想要的书,可以把书按照某个方式来排列。比如将书架分成N层,(卡通书在第一层,文学书在第二层......)不同种类的书放在书架的不同层里。
这就是对数据结构通俗的一种理解。
Python的数据结构分类
Python中的数据结构可以统称为容器(container,即存放数据的容器),它有三种类型:序列(列表和元组),集合(Set)和映射(如字典):
列表List 例如: list1 = ['p', 'y', 't', 'h', 'o', 'n']
元组Tuple 例如: tuple1 = ('p', 'y', 't', 'h', 'o', 'n')
集合Set 例如: set1={'p', 'y', 't', 'h', 'o', 'n'}
字典Dict 例如: dict1 ={1:'p', 2:'y', 3:'t', 4:'h', 5:'o', 6:'n'}