新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

Python中append的用法是什么,python append用法

发布时间:2023-11-15 00:56:17

Python中append的用法是甚么

在Python中,append()是一种列表方法,用于在列表的末尾添加元素。其语法为:

list.append(element)

其中,list是要操作的列表,element是要添加的元素。

例如:

fruits = ['apple', 'banana', 'orange']
fruits.append('grape')
print(fruits)

输出:

['apple', 'banana', 'orange', 'grape']

append()方法会将元素添加到列表的末尾,如果想在列表的指定位置添加元素,可使用insert()方法。