---
title: "Python List"
author: "fairy_xzc"
date: "2016-09-28T09:55:51Z"
tags: []
categories: ["编程语言"]
slug: "python-list"
draft: false
lastmod: "2016-09-28T09:56:30Z"
id: 2327491
url: "https://agilestyle.iteye.com/blog/2327491"
---

**原创转载请注明出处：[http://agilestyle.iteye.com/blog/2327491](/blog/2327491)**

 

list是一种有序的集合，可以随时添加和删除其中的元素。

list.py

```
classmates = ['Michael', 'Kobe', 'Kevin']
print(classmates)

#['Michael', 'Kobe', 'Kevin']
print(len(classmates))

#Michael
print(classmates[0])
#Kobe
print(classmates[1])
#Kevin
print(classmates[2])
#Kevin
print(classmates[-1])

#['Michael', 'Kobe', 'Kevin', 'Tim']
classmates.append("Tim")
print(classmates)
#Tim
print(classmates.pop())
#Kobe
print(classmates.pop(1))

#['Michael', 'Tracy']
classmates[1] = 'Tracy'
print(classmates)

#['Michael', 'James', 'Tracy']
classmates.insert(1, 'James')
print(classmates)

emptyList = []
print(emptyList)
print(len(emptyList))
```

 

Console Output

![](http://dl2.iteye.com/upload/attachment/0120/2843/4df1ccd6-3dbb-38bf-a3fc-7b367b7bcbb2.png)