python list
时间: 2023-10-05 07:11:47 浏览: 75
python中list列表的高级函数
5星 · 资源好评率100%
A Python list is a collection of elements that are ordered and changeable. Lists are created by enclosing elements within square brackets and separating them with commas. Here is an example of a Python list:
```
fruits = ["apple", "banana", "cherry", "orange"]
```
This list contains four elements, which are strings. The elements are ordered, which means that they are indexed starting from 0. The first element in this list is "apple", which has an index of 0. The second element is "banana", which has an index of 1, and so on.
Lists are also changeable, which means that elements can be added, removed, or modified. For example, we can add a new element to the end of the list like this:
```
fruits.append("pear")
```
This will add the string "pear" to the end of the list, making it five elements long. We can also remove an element from the list like this:
```
fruits.remove("cherry")
```
This will remove the string "cherry" from the list, making it only four elements long.
阅读全文