Python数据分析(中英对照)·Sequences 序列

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

1.2.1:Sequences 序列

在Python中,序列是按位置排序的对象集合。
In Python, a sequence is a collection of objects ordered by their position.
在Python中,有三个基本序列,即列表、元组和所谓的“范围对象”。
In Python, there are three basic sequences,which are lists, tuples, and so-called "range objects".
但是Python也有额外的序列类型来表示字符串之类的东西。
But Python also has additional sequence types for representing things like strings.
关于序列的关键方面是,任何序列数据类型都将支持公共序列操作。
The crucial aspect about sequences is that any sequence data type will support the common sequence operations.
但是,除此之外,这些不同的类型将有自己的方法可用于执行特定的操作。
But, in addition, these different types will have their own methods available for performing specific operations.
序列被称为“序列”,因为它们包含的对象形成了一个序列。
Sequences are called "sequences" because the objects that they contain form a sequence.
让我们以图表的形式来看。
So let’s look at this as a diagram.
假设这是我们的序列,在这个例子中,序列中有一些不同的对象——三角形、正方形和圆形。
Imagine that this is our sequence, and we have a few different objects in our sequence here– triangles, squares,and circles, in this example.
要理解序列的第一个基本方面是索引从0开始。
The first, fundamental aspect to understand about sequences is that indexing starts at 0.
因此,如果我们称这个序列为“s”,我们将通过键入“s”来访问序列中的第一个元素,并在括号中放入它的位置,即0。
So if we call this sequence "s", we would access the first element in our sequence by typing "s" and, in brackets, putting its location, which is 0.
这个位于第二个位置的对象将作为s[1]进行寻址和访问,依此类推。
This object here in the second position would be addressed and accessed as s[1], and so on.
这将是s2,3和4。
This would be s 2, 3, and 4.
访问序列中对象的另一种方法不是从左向右计数,而是从右向左计数。
Another way to access objects within the sequence is not to count from left to right, but from right to left.
所以我们可以通过给出一个正的索引来访问序列,这是从左到右计数一个位置,或者我们可以使用一个负的索引,这是从右到左计数位置。
So we can access sequences either by giving a positive index, which is counting a location from the left to right,or we can use a negative index, which is counting positions from right to left.
在这种情况下,我们必须对序列中的最后一个对象使用负1。
In that case, we have to use the negative 1 for the very last object in our sequence.
相应地,负2对应于倒数第二个对象,依此类推。
Correspondingly, minus 2 would correspond to the second to last object, and so on.
序列还支持称为“切片”的操作
Sequences also support an operation called "slicing."
现在让我们来看一看。
So let’s take a look at that now.
如果我们再次拥有序列“s”。要访问特定的单元、特定的对象,我们只需要使用位置——例如,在本例中为2。
If we, again, have our sequence "s". To access a specific unit, specific object, we would just use the location– for example, 2, in this case.
但是,如果我们想提取序列中的多个对象,我们可以执行以下操作。
However, if we wanted to extract multiple objects in the sequence,we can do the following.
我们可以说s括号,比如说,0,2。
We can say s bracket, say, 0, 2.
这是第一个索引,第一个位置是起始位置,第二个位置是停止位置。
This first index, the first position is the start position,and the second position here is to stop position.
Python切片在Python到达停止位置的元素之前停止。
Python slices stop before Python reaches the element at the stop location.
这意味着,如果键入“s”,并在括号中键入“0 column 2”,Python将返回一个包含位置0和1中的对象的切片,但不会返回位置2处的对象。
This means that if you type "s", and, in brackets, "0 column 2",Python is going to return a slice to which consists of the objects in locations 0 and 1,but it will not return to you the object at location 2.

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

常见问题FAQ

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

提供最优质的资源集合

立即加入 友好社区
×