今天的学习内容是python中的列表的相关内容。
一.创建列表
1.创建一个普通列表
>>> tabulation1 = ['大圣','天蓬','卷帘']
>>> tabulation1
['大圣', '天蓬', '卷帘']
>>> tabulation2 = [72,36,18]
>>> tabulation2
[72, 36, 18]
2.创建一个混合列表
>>> mix tabulation = ['大圣',72,'天蓬',36]
SyntaxError: invalid syntax
>>> mixtabulation = ['大圣',72,'天蓬',36]
>>> mixtabulation
['大圣', 72, '天蓬', 36]
3.创建一个空列表
>>> empty = []
>>> empty
[]
三种方式就介绍给大家了,接下来,如果想向列表中添加元素,该怎么办呢?
二.向列表中添加元素
1.append
>>> tabulation1.append('紫霞')
>>> tabulatio