Python之列表的插入&替换修改方法

yipeiwu_com6年前Python基础

用例子说明

fruit = ['pineapple','grape','pear']

fruit[0:0] = ['Orange']  #在fruit集合中第一位插入字符串'Orange'

print(fruit)     #['Orange','pineapple','grape','pear']

fruit[0] = 'Grapefruit'  #将fruit集合的第一位元素替换为'Grapefruit'

print(fruit)     #['Grapefruit','pineapple','grape','pear']

fruit[0:0] = 'Grapefruit'      

print(fruit) #['G','r','a','p','e','f','r','u','i','t','Grapefruit','pineapple','grape','pear']

以上这篇Python之列表的插入&替换修改方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python 判断自定义对象类型

要判断自定义对象的类型,用__class__方法,或者用isinstance(object, class-or-type-or-tuple)-->bool 用__class__不能...

Python psutil模块简单使用实例

安装很简单 复制代码 代码如下: pip install psutil 官网地址为: https://pythonhosted.org/psutil/ (文档上有详细的api) git...

Python 多线程搜索txt文件的内容,并写入搜到的内容(Lock)方法

废话不多说,直接上代码吧! import threading import os class Find(threading.Thread): #搜索数据的线程类 def __i...

Python中处理字符串之islower()方法的使用简介

 islower()方法判断检查字符串的所有的字符(字母)是否为小写。 语法 以下是islower()方法的语法: str.islower() 参数  ...

python类的实例化问题解决

python类的实例化问题解决

类的实例化问题解决 运行结果: line 21, in <module> s=speaker('ken',10,'aaa') TypeError: __init__(...