对python中的pop函数和append函数详解
作者:三支烟 时间:2021-10-09 09:11:32
pop()函数
1、描述
pop() 函数用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值。
语法
pop()方法语法:
list.pop(obj=list[-1])
2、参数
obj – 可选参数,要移除列表元素的对象。
3、返回值
该方法返回从列表中移除的元素对象。
4、实例
以下实例展示了 pop()函数的使用方法:
#!/usr/bin/python
aList = [123, 'xyz', 'zara', 'abc'];
print "A List : ", aList.pop();
print "B List : ", aList.pop(2);
以上实例输出结果如下:
A List : abc
B List : zara
append()函数
1、描述
Python列表append()方法用于将传入的对象附加(添加)到现有列表中。
2、语法
以下是append()方法的语法 -
list.append(obj)
Python
3、参数
obj - 这是要添加到列表中的对象。
4、返回值
此方法不返回任何值,但更新现有列表。
5、示例
以下示例显示了append()方法的用法。
#!/usr/bin/python3
list1 = ['C++', 'Java', 'Python']
list1.append('C#')
print ("updated list : ", list1)
Python
当运行上面的程序,它产生以下结果 -
updated list : ['C++', 'Java', 'Python', 'C#']
Gif 演示 Python while 语句执行过程
来源:https://blog.csdn.net/qq_36357820/article/details/77527081
标签:python,pop,append
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python去除拼音声调字母,替换为字母的方法
2022-02-13 10:43:55
用户体验至上的网页设计秘笈
2007-09-07 10:16:00
啥是佩奇?使用Python自动绘画小猪佩奇的代码实例
2022-02-13 19:46:53
![](https://img.aspxhome.com/file/2023/5/86375_0s.gif)
php 无法载入mysql扩展
2023-09-07 13:07:40
Python爬取科目四考试题库的方法实现
2023-02-14 00:29:39
![](https://img.aspxhome.com/file/2023/0/70220_0s.jpg)
转换字符串单词的第一个字母为大写
2007-10-18 10:50:00
Asp模板制作方法详解
2007-10-11 19:05:00
利用Python将文本中的中英文分离方法
2023-01-06 11:55:58
ASP编码问题的深入研究与解决方案(MSDN)
2007-10-25 11:54:00
python中如何实现将数据分成训练集与测试集的方法
2022-10-03 23:11:45
详解Python自建logging模块
2023-12-21 02:28:50
Django的分页器实例(paginator)
2023-06-23 03:22:35
解决启动django,浏览器显示“服务器拒绝访问”的问题
2023-08-20 05:45:01
![](https://img.aspxhome.com/file/2023/5/93485_0s.jpg)
Python 命令行非阻塞输入的小例子
2023-12-09 19:48:29
Python数字图像处理代数之加减乘运算
2023-03-20 07:51:26
![](https://img.aspxhome.com/file/2023/7/82667_0s.png)
python使用分治法实现求解最大值的方法
2021-07-14 12:06:09
Python生成指定数量的优惠码实操内容
2021-06-12 18:29:25
![](https://img.aspxhome.com/file/2023/5/78465_0s.png)
asp Access数据备份,还原,压缩类代码
2011-03-07 11:16:00
python超详细实现完整学生成绩管理系统
2022-08-25 08:59:08
![](https://img.aspxhome.com/file/2023/5/82775_0s.png)
python获取网页中所有图片并筛选指定分辨率的方法
2021-07-28 04:57:23
![](https://img.aspxhome.com/file/2023/6/71446_0s.jpg)