##Data Structure##
##2018/4/8##
#数据结构(Data Structures)基本上人如其名——它们只是一种结构,能够将一些数据聚合
#在一起。换句话说,它们是用来存储一系列相关数据的集合。
#Python 中有四种内置的数据结构——列表(List)、元组(Tuple)、字典(Dictionary)和集
#合(Set)。我们将了解如何使用它们,并利用它们将我们的编程之路变得更加简单。
##Point1##
##列表----List##
##一种用于保存一系列有序项目的集合,也就是说,你可以利用列表保存一串项目的序列
#项目的列表应该用方括号括起来,这样 Python 才能理解到你正在指定一张列表。一旦你创建
#了一张列表,你可以添加、移除或搜索列表中的项目。既然我们可以添加或删除项目,我们
#会说列表是一种可变的(Mutable)数据类型,意即,这种类型是可以被改变的。
##e.g.1
print('e.g.1')
shopping_list = ['meat','egg','milk','tomato']
print('I hava',len(shopping_list),'items to purchase')
print('These items are ',end = ' ')
for item in shopping_list:
print(item,end = ' ')
print('\nI also have to buy rice.')
shopping_list.append('rice')
print('Now my shoplist is ',shopping_list)
print('I will sort my list now')
shopping_list.sort()
print('Sorted shopping list is',shopping_list)
print('The first item I will buy is',shopping_list[0])
olditem = shopping_list[0]
del shopping_list[0]
print('I bought the ',olditem)
print('My shopping list is now',shopping_list)
print('---------------------
Byte of Python-----Data Structure
最新推荐文章于 2024-06-28 19:30:00 发布