Python中列表的基本操作包括:
访问元素 :使用下标索引访问列表中的值。
```python
fruits = ['banana', 'apple', 'cherry', 'pear', 'fig']
print(fruits) 输出 'banana'
添加元素
`append(object)`:将值`object`添加到列表的末尾。
```python
fruits.append('peach')
print(fruits) 输出 ['banana', 'apple', 'cherry', 'pear', 'fig', 'peach']
`extend(iterable)`:将另一个可迭代对象中的元素添加到列表的末尾。
```python
more_fruits = ['lemon', 'orange']
fruits.extend(more_fruits)
print(fruits) 输出 ['banana', 'apple', 'cherry', 'pear', 'fig', 'peach', 'lemon', 'orange']
`insert(index, object)`:在指定位置`index`前插入元素`object`。
```python
fruits.insert(0, 'lemon')
print(fruits) 输出 ['lemon', 'banana', 'apple', 'cherry', 'pear', 'fig', 'peach', 'orange']
修改元素:
直接通过下标赋值修改列表中的元素。
```python
fruits = 'grape'
print(fruits) 输出 ['grape', 'apple', 'cherry', 'pear', 'fig', 'peach', 'orange']
删除元素
`del`:根据下标删除元素。
```python
del fruits
print(fruits) 输出 ['grape', 'cherry', 'pear', 'fig', 'peach', 'orange']
`pop(index)`:移除列表中指定位置的元素,并返回该元素的值。
```python
removed_fruit = fruits.pop(2)
print(removed_fruit) 输出 'pear'
print(fruits) 输出 ['grape', 'cherry', 'fig', 'peach', 'orange']
`remove(object)`:移除列表中第一个匹配的元素。
```python
fruits.remove('cherry')
print(fruits) 输出 ['grape', 'fig', 'peach', 'orange']
列表操作符
`+`:组合两个列表。
```python
fruits1 = ['banana', 'apple']
fruits2 = ['cherry', 'pear']
combined_fruits = fruits1 + fruits2
print(combined_fruits) 输出 ['banana', 'apple', 'cherry', 'pear']
`*`:重复列表中的元素。
```python
repeated_fruits = ['apple'] * 3
print(repeated_fruits) 输出 ['apple', 'apple', 'apple']
其他操作
`len(list)`:获取列表长度。
```python
print(len(fruits)) 输出 5
`in`:检查元素是否在列表中。
```python
print('apple' in fruits) 输出 True
`for`循环遍历列表。
```python
for fruit in fruits:
print(fruit)
以上是Python列表的一些基本操作。