Home > Backend Development > Python Tutorial > Python列表计数及插入实例

Python列表计数及插入实例

WBOY
Release: 2016-06-10 15:18:29
Original
1425 people have browsed it

本文实例讲述了Python列表计数及插入的用法。分享给大家供大家参考。具体如下:

复制代码 代码如下:
word=['a','b','c','d','e','f','g']//首个元素为元素0,word[0]=a  
a=[num1:num2]                                    
//从num1到num2的元素(不包括元素num2)    
//若为负数,则代表倒数第几个
 
在对list进行操作时,append 追加,word.append(elements)
elements是独立的,若为list时作为一个整体追加在word的后面,而不是延长word,
word.extend(elements)是延长,将elements包含的元素延长在word的后面insert(),插入:
复制代码 代码如下:
word.insert(mum,elements)
所插入的也是也是一个整体。

希望本文所述对大家的Python程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template