龙空技术网

学习知多少(python篇):列表

LearningYard学苑 153

前言:

目前咱们对“python列表的定义”都比较关怀,我们都想要了解一些“python列表的定义”的相关内容。那么小编同时在网络上收集了一些关于“python列表的定义””的相关资讯,希望小伙伴们能喜欢,兄弟们快快来了解一下吧!

分享兴趣,传播快乐,增长见闻,留下美好!

亲爱的您,这里是LearningYard学苑。今天小编为大家带来“学习知多少(python篇):列表”,欢迎您的访问。

Share interests, spread happiness, increase knowledge, and leave a good legacy!

Dear you, this is The LearningYard Academy. Today Xiaobian brings you "Learn how much to know (python):list”, welcome your visit.

一、定义

列表是最重要的python内置对象之一,是包含若干元素的有序连续内存空间。

I. Definitions

A list is one of the most important Python built-in objects, an ordered contiguous memory space containing several elements.

二、列表创建与删除

使用“=”直接将一个列表赋值给变量

使用list()函数把元组、字符串、字典等转换为列表

使用del命令将列表删除

2. List creation and deletion

Use "=" to assign a list directly to a variable

Use the list() function to convert tuples, strings, dictionaries, etc. to lists

Use the del command to delete the list

三、列表常用方法

append(x)

将x追加至列表尾部

extend(L)

将列表L中的所有元素追加至列表尾部

insert(index,x)

在列表index处插入x,如果index为正数且大于列表长度则在尾部追加x,如果index为负数且小于列表长度的相反数则在列表头部插入x。

remove(x)

在列表中删除第一个值为x的元素,如果不存在x则抛出异常

reverse()

对列表所有元素进行原地排序,首尾交换

3. Common methods of listing

append(x)

Append x to the end of the list

extend(L)

Appends all elements in list L to the end of the list

insert(index,x)

Insert x at the list index, append x to the trailing if index is positive and greater than the list length, and insert x at the end if index is negative and less than the opposite of the list length.

remove(x)

Remove the first element with a value x in the list and throw an exception if x does not exist

reverse()

Sort all elements of the list in place, ending and swapping

四、案例

4. Cases

今天的分享就到这里了。

如果您对今天的文章有独特的想法,

欢迎给我们留言,

让我们相约明天。

祝您今天过得开心快乐!

That's all for today's sharing.

If you have a unique idea for today’s article,

please leave us a message,

and let us meet tomorrow.

I wish you a happy day !

本文由learningyard新学苑原创,如有侵权,请联系我们!

翻译来源于谷歌翻译

部分来源于

百度文库

清华大学出版 董付国《Python程序设计基础》

编辑&排版|百味

审核|闫庆红

标签: #python列表的定义