博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python列表| 带有示例的append()方法
阅读量:2528 次
发布时间:2019-05-11

本文共 1583 字,大约阅读时间需要 5 分钟。

list.append()方法 (list.append() Method)

append() is an inbuilt method in Python, which is used to add an element/item to the list. append() adds the element at the end.

append()是Python中的一种内置方法,用于将元素/项目添加到列表中。 append()在最后添加元素。

Syntax:

句法:

list.append(element)

Here,

这里,

  • list is the name of the list.

    list是列表的名称。

  • element is an item/element to be appended.

    元素是要附加的项目/元素。

Return type: Method append() does not return any value, it just modifies the existing list.

返回类型:方法append()不返回任何值,它仅修改现有列表。

Example:

例:

# Python program to demonstrate# an example of list.append() method # listcities = ['New Delhi', 'Mumbai']# print the listprint "cities are: ",cities# append two more citiescities.append('Bangalore');cities.append('Chennai');# print the updated listprint "cities are:",cities

Output

输出量

cities are:  ['New Delhi', 'Mumbai']    cities are: ['New Delhi', 'Mumbai', 'Bangalore', 'Chennai']

Explanation:

说明:

  • Initially there were two elements in the list ['New Delhi', 'Mumbai']

    最初,列表中有两个元素['New Delhi','Mumbai']

  • Then, we added two more city names (two more elements) - 1) 'Bangalore' and 2) 'Chennai', by using following python statements:

    然后,我们使用以下python语句添加了另外两个城市名称(另外两个元素)-1) 'Bangalore'和2) 'Chennai'

cities.append('Bangalore');    cities.append('Chennai');
  • 'Bangalore' and the 'Chennai' will be added at the end of the list named cities.

    “班加罗尔”“钦奈”将添加到名为城市的列表的末尾。

  • Then, we printed the updated list; the output will be a new list with 4 elements ['New Delhi', 'Mumbai', 'Bangalore', 'Chennai'].

    然后,我们打印了更新的列表; 输出将是一个包含4个元素的新列表['New Delhi','Mumbai','Bangalore','Chennai']

  • 翻译自:

转载地址:http://wivzd.baihongyu.com/

你可能感兴趣的文章
2016年1月全国网络媒体技术联盟第七届年会的几个关键词
查看>>
BugBugBugBugBugBugBugBugBugBugBugBugBugBugBug
查看>>
LINUX 编译安装 PHP 环境
查看>>
Vue开源项目库汇总-转
查看>>
作业4(第二部分)
查看>>
我需要一个足够大的桌子
查看>>
[BZOJ4523]路由表
查看>>
js 正则,从url中取参数值
查看>>
《Head First Servlets & JSP》-11-Web应用部署
查看>>
android之volley学习
查看>>
C++中析构函数的作用,
查看>>
Jupyter
查看>>
java中long类型转换为int类型
查看>>
Viewbox在UWP开发中的应用
查看>>
给你的应用“一只”智慧的眼睛 —— Barcode常识普及以及识别信息处理
查看>>
PHP基础知识点汇总(三)
查看>>
排序算法
查看>>
sql server系统数据库,temp库的用途
查看>>
推荐一下干货-------为什么你的app不耐看
查看>>
05-数据类型转换
查看>>