python自带了四种数据结构：列表、字典、元组、集合，本章主要介绍第一种：列表。

# 1、in操作符

```            ```
if a in A：
print(a)
if a not in B:
print(a)
```
```

append函数：

remove函数：

pop函数：

extend函数：

insert函数：

# 3、练习

```            ```
phrase="Don't panic"
plist=list(phrase)
print(phrase)
print(plist)
delspace=plist.pop(5)
plist.remove('D')
plist.remove("'")
deln=plist.pop(1)
plist.remove('n')
plist.remove('i')
plist.remove('c')
plist.insert(1,deln)
plist.insert(2,delspace)
dela=plist.pop()
plist.insert(4,dela)
new_phrase=''.join(plist)
print(plist)
print(new_phrase)
```
```

```            ```
phrase="Don't panic"
plist=list(phrase)
print(phrase)
print(plist)
for i in range(3):
plist.pop()
plist.pop(0)
plist.remove("'")
plist.extend([plist.pop(),plist.pop()]
plist.insert(2,plist.pop(3))
new_phrase=''.join(plist)
print(plist)
print(new_phrase)
```
```

```            ```
plist.extend([plist.pop(),plist.pop()]
```
```

# 4、列表的复制

```            ```
A=[1,2,3]
B=A
```
```

```            ```
A=[1,2,3]
B=A.copy()
```
```

# 5、列表的索引

```            ```
A="Don't panic!"
A[0:10:3]#返回D'pi
A[3:]#返回't panic!
A[:10]#返回Don't pani
A[::2]#返回Dntpnc
```
```

# 6、练习

```            ```
phrase="Don't panic!"
plist=list(phrase)
print(phrase)
print(plist)
plist1=plist[1:3]
print(plist1)
plist2=plist[5:3:-1]
print(plist2)
plist3=plist[7:5:-1]
print(plist3)
plist1.extend(plist2)
plist1.extend(plist3)
plist=plist1.copy()
phrase=''.join(plist)
print(plist)
print(phrase)
```
```

```            ```
phrase="Don't panic!"
plist=list(phrase)
print(phrase)
print(plist)
new_phrase=''.join(plist[1:3])
new_phrase=new_phrase+''.join([plist[5],plist[4],plist[7],plist[6]])
print(plist)
print(new_phrase)
```
```

# 7、列表的迭代

```            ```
A="Hello world!"
for char in A[:-3]:
print('\t',char)
print()
for char in A[-7:]:
print('\t'*2,char)
print()
for char in A[::-3]:
print('\t'*3,char)

```
```

QQ号联系： 360901061

【本文对您有帮助就好】