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设计】。

相关文章

matplotlib简介,安装和简单实例代码

matplotlib简介,安装和简单实例代码

官网介绍: Matplotlib is a Python 2D plotting library which produces publication quality figures i...

儿童学习python的一些小技巧

以下是一些Python实用技巧和工具,希望能对大家有所帮助。 交换变量 x = 6 y = 5 x, y = y, x print x >>> 5 print...

Python原始字符串与Unicode字符串操作符用法实例分析

Python原始字符串与Unicode字符串操作符用法实例分析

本文实例讲述了Python原始字符串与Unicode字符串操作符用法。分享给大家供大家参考,具体如下: #coding=utf8 ''''' 在原始字符串里,所有的字符串都是直接按照...

Django自定义认证方式用法示例

本文实例讲述了Django自定义认证方式。分享给大家供大家参考,具体如下: 创建登录应用 首先创建一个新的login app,用来存放认证用到代码 python manage.py...

django url到views参数传递的实例

一、采用?a=1&b=2访问 修改views.py: views.py from django.shortcuts import render from django.http im...