# Python 中的 list 是一种有序的、可变的数据类型,可以存储多个元素。列表中的元素可以是不同类型的,并且可以通过索引进行访问和修改。
# 创建一个空列表
empty_list = []
print(empty_list) # 输出: []
# 创建一个包含多个元素的列表
fruits = ['apple', 'banana', 'cherry']
print(fruits) # 输出: ['apple', 'banana', 'cherry']
# 访问列表中的元素
first_fruit = fruits[0]
print(first_fruit) # 输出: apple
# 修改列表中的元素
fruits[1] = 'orange'
print(fruits) # 输出: ['apple', 'orange', 'cherry']
# 列表中添加元素
fruits.append('grape')
print(fruits) # 输出: ['apple', 'orange', 'cherry', 'grape']
# 删除列表中的元素
del fruits[0]
print(fruits) # 输出: ['orange', 'cherry', 'grape']
# 列表切片
sublist = fruits[1:3]
print(sublist) # 输出: ['cherry', 'grape']
上一篇:python运算符重载
下一篇:python 输出时间
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站