金点网络-全网资源,一网打尽
  • 网站首页
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
登录/注册
  • 专享大神特权
立即开通开通会员抄底价

Python数据分析(中英对照)·Lists 列表

作者 : jamin 本文共6308个字,预计阅读时间需要16分钟 发布时间: 2020-10-18 共1059人阅读

1.2.2: Lists 列表

列表是任何类型的对象的可变序列。
Lists are mutable sequences of objects of any type.
它们通常用于存储同质项目。
And they’re typically used to store homogeneous items.
列表是序列的一种类型,就像字符串一样,但它们确实有区别。
Lists are one type of sequence, just like strings but they do have their differences.
如果我们比较字符串和列表,一个区别是字符串是单个字符的序列,
If we compare a string and a list, one difference is that strings are sequences of individual characters,
而列表是任何类型Python对象的序列。
whereas lists are sequences of any type of Python objects.
字符串和列表之间的另一个区别是字符串是不可变的,而列表是可变的。
Another difference between strings and lists is that strings are immutable, whereas lists are mutable.
除了这两个区别之外,字符串和列表当然也有自己的方法。
In addition to these two differences, strings and lists, of course,come with their own methods.
通常情况下,列表只包含一种类型的对象,尽管这不是严格的要求。
It is common practice for a list to hold objects of just one type,although this is not strictly a requirement.
让我们尝试几个简单的列表来测试它们。
Let’s try a couple of simple lists to experiment with them.
让我们构造一个简单的数字列表,以进一步了解列表。
Let’s construct a simple list of numbers to learn a little bit more about lists.
所以我要构造一个数字列表。
So I’m going to construct a list of numbers.
我要称之为数字。
I’m going to call it numbers.
我将使用数字2、4、6和8。
And I’ll use numbers 2, 4, 6, and 8.
假设我想提取或访问列表中的第一个元素。
Imagine I wanted to extract, or access, the first element of my list.
我要做的第一件事是键入列表的名称,然后我需要方括号。
The first thing for me to do is type the name of the list,then I need my square brackets.
现在请记住,在Python中,索引从零开始。
Now remember, in Python, indexes start at zero.
因此,为了能够查看该列表的第一个元素,我需要将其放入索引0,位置0。
So for me to be able to look at the first element of that list,I need to put in index 0, position 0.
在这里,Python告诉我第一个对象,即位于位置0的对象,是数字2。
Here, Python tells me that the first object, meaning the object located at position 0, is number 2.
如果我将索引更改为1,Python将给我第二个对象。
If I change the index to 1, Python gives me the second object.
现在,如果我想知道列表上最后一个对象是什么,我可以从右到左计算位置。
Now if I wanted to find out what is the very last object on my list,I can count positions from right to left.
这意味着我必须使用负指数。
And that means I have to use negative indices.
因此,如果我键入数字减1,Python告诉我列表中最后一个元素是数字8。
So if I type numbers minus 1, Python tells me the very last element of my list is the number 8.
记住,因为列表是可变序列,所以我们可以在创建它们之后修改它们的内容。
Remember, because lists are mutable sequences, we can modify their content and after we’ve created them.
让我们试着在列表的末尾添加一个新的数字,一个数字10。
Let’s try appending a new number, a number 10, to the end of our list.
要做到这一点,我首先键入数字,然后需要点,然后键入append。
To do that, the first thing I type is numbers, then I need my dot,and I type append.
在括号里,我输入了数字10。
And inside the parentheses, I put in the number 10.
如果我现在要求Python显示列表的内容,我将看到数字10已附加到该列表中。
If I now ask Python to show the content of the list,I’ll see that number 10 has been appended to that list.
我们通常希望执行的另一个操作是将两个或多个列表连接在一起。
Another operation we commonly would like to do is to concatenate two or more lists together.
现在考虑一个情况,我有另一个列表。
Now consider a situation where I have another list.
我们就叫它x吧。
Let’s just call that x.
让我们假设新的列表有数字12、14和16。
And let’s say the new list has numbers 12, 14, and 16.
在Python中,只要两个对象都是列表,我就可以使用加号来连接它们。
In Python, I can use the plus sign as long as both objects are lists to concatenate them.
所以我可以输入数字加x。
So I can type numbers plus x.
你可以看到结果是另一个列表。
And you see that the result is another list.
我可以问一下,Python最近输出的对象是什么类型的?
I can check that by asking, what is the type of the object that Python most recently outputted?
这是一个列表。
And that’s a list.
因此,当我键入一个列表和另一个列表时,我将这两个列表连接在一起。
So when I type a list plus another list, I’m concatenating these two lists together.
现在,让我们更详细地了解两种列表方法。
Let’s now look at a couple of list methods in a little bit more detail.
在这种情况下,我们有一个数字列表。
In this situation, we have a numbers list.
我想做的是,我想反转列表的内容。
And what I would like to do is, I would like to reverse the content of the list.
所以我想把我的最后一个物体放在第一位,第二个物体放在第二位,以此类推。
So I would like to have my last object first, second to last object second,and so on.
在这种情况下,我可以使用反向方法。
In this case, I can use the reverse method.
所以我可以输入数字,我可以调用反向方法。
So I can type numbers, and I can call the reverse method.
但是请看,Python不会向我返回任何对象。
But see, Python doesn’t return any object to me.
这是因为列表方法就是所谓的就地方法。
This is because list methods are what are called in-place methods.
他们修改了原始列表。
They modify the original list.
为了了解这一点,我现在可以输入数字,我可以看到列表上的数字已经颠倒了。
To see that, I can now type numbers, and I can see that the numbers on the list have been reversed.
这就是发生的事情。
So this is what happens.
如果我们这里有一个列表,我们有我们的数字1,3,等等。
If we have a list here – we have our numbers 1, 3, and so on.
我们最后的号码是23。
Our last number is 23.
反向方法的作用如下:
What the reverse method does is the following:
它在我的列表上运行,意思是原始列表。
It operates on the list that I have, meaning the original list.
它首先移动最后一个对象,最后移动第一个对象。
It moves the last object first and the first object last.
然后将第二个到最后一个对象移动到第二个位置,依此类推。
Then it takes the second to last object, moves that to the second position,and so on.
因此,结果是列表中对象的顺序到最后将被颠倒。
So the consequence is that the ordering of the objects in the list will have been reversed by the end.
然后让我们看一下排序方法。
Let’s then a look at the sort method.
考虑一个名为名字的列表,我们有四个名字,ZoFiA,亚历克斯,摩根和安东尼。
Consider a list called names where we have four names, Zofia, Alex,Morgan, and Anthony.
列表方法之一称为排序方法。
One of the list methods is called the sort method.
如果我键入names.sort并在sort的末尾加上括号,我就可以对该列表的内容进行排序。
If I type names.sort and place parentheses at the end of sort,I can sort the contents of this list.
如果我现在键入名称,您将看到名称已按字母顺序排序。
If I now type names, you’ll see that names have been sorted to be in alphabetical order.
因此,列表中对象的新顺序是Alex、Anthony、Morgan和Zofia。
So the new ordering of objects in the list is Alex, Anthony, Morgan, and Zofia.
现在Python中还有另一个函数叫做“sorted”。
Now there is another function in Python which is called "sorted".
函数的运行方式有点不同。
And the way that function operates is a little bit different.
当我们使用list方法sort时,我们将获取现有列表并重新排序该列表中的对象。
When we’re using the list method sort, we’re taking the existing list and reordering the objects within that list.
如果我们使用sorted函数,我们实际上是在要求Python构造一个全新的列表。
If we’re using the sorted function, we’re actually asking Python to construct a completely new list.
它将使用前一个列表中的对象构造此新列表,以使新列表中的对象
It will construct this new list using the objects in the previous list in such a way that the objects in the new list
将按排序顺序显示。
will appear in a sorted order.
让我们看看这是怎么发生的。
So let’s see how this happens.
让我看看我的名单,让我把它颠倒过来。
Let me take my names list, and let me just reverse that.
为了确认发生了什么,现在订单已经如我们预期的那样被翻转了。
And to confirm what has happened, now the ordering has been flipped as we would expect.
然后我可以说一些类似于排序的名称,这将是一个新对象。
I can then say something like sorted_names,which would be a new object.
我使用排序函数,并将其应用于我的列表名。
I use the sorted function and I apply it to my list names.
现在如果我看到名字的内容,你会看到什么都没有发生。
Now if I see what is the content of names,you see that nothing has happened.
那是因为我没有调用任何列表方法。
That’s because I haven’t called any list method.
但是如果我看一下排序的名称的内容,你会发现它的对象与原始列表名称完全相同,
But if I look at the contents of sorted_names,you’ll see that it has the same exact objects as the original list names,
但在这种情况下,它们是按字母顺序排序的。
but in this case, they have been alphabetically sorted.
最后,如果您想知道列表包含多少对象,我们可以使用一个通用的序列函数len。
Finally, if you wanted to find out how many objects our list contains,we can use a generic sequence function, len.
因此,我们可以键入len(names),Python告诉我们,我们的列表包含四个对象。
So we can type len(names), and Python tells us that our list contains four objects.

Python 数据分析
本站所提供的部分资源来自于网络,版权争议与本站无关,版权归原创者所有!仅限用于学习和研究目的,不得将上述内容资源用于商业或者非法用途,否则,一切后果请用户自负。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源。如果上述内容资对您的版权或者利益造成损害,请提供相应的资质证明,我们将于3个工作日内予以删除。本站不保证所提供下载的资源的准确性、安全性和完整性,源码仅供下载学习之用!如用于商业或者非法用途,与本站无关,一切后果请用户自负!本站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。如有侵权、不妥之处,请联系站长以便删除!
金点网络-全网资源,一网打尽 » Python数据分析(中英对照)·Lists 列表

常见问题FAQ

免费下载或者VIP会员专享资源能否直接商用?
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
是否提供免费更新服务?
持续更新,永久免费
是否经过安全检测?
安全无毒,放心食用
jamin

jamin 大神

下一篇
网络协议-组播介绍

相关推荐

Python数据分析(中英对照)·Classes and Object-Oriented Programming类和面向对象编程

Python数据分析(中英对照)·Classes and Object-Oriented Programming类和面向对象编程

Python数据分析(中英对照)·Python Basics Python 基础

Python数据分析(中英对照)·Python Basics Python 基础

Python数据分析(中英对照)·Objects 对象

Python数据分析(中英对照)·Objects 对象

Python数据分析(中英对照)·Plotting Using Logarithmic Axes-使用对数轴绘图

Python数据分析(中英对照)·Plotting Using Logarithmic Axes-使用对数轴绘图

Python数据分析(中英对照)·Building and Examining NumPy Arrays 构建和检查 NumPy 数组

Python数据分析(中英对照)·Building and Examining NumPy Arrays 构建和检查 NumPy 数组

标签云
Android Atom ExecutorService ForkJoin GM GM后台 GM授权后台 H5 Java Javascript Linux手工服务端 pipbestcom Python ReentrantLock synchronized ThreadLocal volatile Win一键即玩服务端 一键端 传奇 写作 创业 单机 后台 商业端 外网 安卓 安卓苹果双端 工具 手工端 手游 搭建教程 教程 数据分析 文案 游戏源码 端游 经典 网单 职场 自媒体 视频教程 详细搭建教程 运营后台 页游

近期文章

  • 回合手游【逍遥西游之繁华西游】最新整理单机一键既玩镜像服务端_Linux手工端_GM后台_教程
  • 最新整理精品回合制手游【天书奇谈3D混沌完整版】VM一键单机版_linux手工外网端_隐盟视频教程_授权GM后台_双端
  • 典藏修真页游【诸仙列传OL】最新整理Win系服务端_GM工具_详细外网搭建教程
  • MT3换皮MH【浮生若梦尊享挂机修复版】最新整理单机一键即玩镜像端_Linux手工服务端_安卓苹果双端_GM后台_详细搭建教程
  • 大话回合手游【最新引擎之缥缈西游渡劫版】最新整理Linux手工服务端_安卓苹果双端_管理后台_CDK后台_详细搭建教程_视频教程

分类

  • | wordpress插件 |
  • | wordpress模板 |
  • | 其它模板 |
  • | 帝国模板 |
  • | 织梦插件 |
  • | 织梦模板 |
  • A5源码
  • Android软件
  • APP引流
  • E语言
  • H5
  • LUA
  • QQ营销
  • SEO推广
  • Windows软件
  • 体育运动
  • 信息数据
  • 创业专题
  • 办公教程
  • 口才演讲
  • 名师讲座
  • 商城/淘客/交易
  • 小吃技术
  • 小说/漫画/阅读
  • 建站教程
  • 引流脚本
  • 影视/音乐/视频
  • 影视资源
  • 微信/微商/微擎
  • 微信小程序
  • 微信营销
  • 微擎模块
  • 手游源码
  • 技能学习
  • 抖音课程
  • 摄影教程
  • 棋牌教程
  • 模板/主题/插件
  • 游戏源码
  • 爆粉引流
  • 理财/金融/货币
  • 生活老师
  • 电商客
  • 电子文档
  • 电脑教程
  • 社群营销
  • 站长工具
  • 精品网单
  • 系统工具
  • 素材资料
  • 综合资料
  • 编程经验
  • 网站源码
  • 网络安全
  • 网赚教程
  • 网赚源码
  • 考研资料
  • 脚本/AI/智能
  • 自媒体
  • 英语学习
  • 营销软件
  • 设计素材
  • 说书小说
  • 贴吧引流
  • 软件工具
  • 软文营销
  • 逆向软件
  • 音频讲座
  • 页游源码

提供最优质的资源集合

立即加入 友好社区
金点网络-全网资源,一网打尽

新一代全网资源综合门户网(www.pipbest.com-金点网络)专注服务于互联网,提供各类最新最全的免费源码下载(PHP、ASP、JSP、.NET),更提供免费工具,免费源码下载,软件下载,素材下载,赚钱教程下载,交流论坛等网站运营相关的一切内容,为网友搜罗最有价值的网站源码下载与技术教程等服务!

服务目录
  • 金点OpenAPI
  • 金点云
  • 金点支付
友情链接
  • 数媒派
  • 国家电网
快速搜索

本站由Nice强力驱动

声明: 本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!

本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!
© 2016-2023 PipBest.Com - 金点网络 & 金点部落. All rights reserved 京ICP备2022005359号-1
  • 关注有礼
  • 签到
  • 客服
    官方QQ群 常见问题 FAQ

    在线客服

    点我联系

    直接说出您的需求!
    切记!带上资源连接与问题!

    工作时间: 9:30-21:30

  • 暗黑
    模式
  • 全屏
  • 投稿
    赚钱
  • 首页

  • 签到

  • 切换

  • 客服

金点网络-全网资源,一网打尽
  • 登录
  • 注册
or
or
忘记密码?
金点网络-全网资源,一网打尽
  • 网站首页 ►
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习 ►
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程 ►
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码 ►
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码 ►
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料 ►
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座 ►
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具 ►
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    ►
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
×
u3** 刚刚下载了 爆款吸金文案训练

    全网资源·一网打尽

  • 金点出品,必属精品!
  • 发布原创内容,获取高额提成!
  • 我们与你共创美好数字生态!
  • 无特殊说明密码默认:pipbest.com