[Python Learning] General Operations of Sequences

Recently, I am going to systematically learn python. In order to find it in time in the future, I will record it first.

Let’s talk about the sequence first. I was using it before, and I feel that this concept is vague. I took a look at it today. The sequence is the most basic data structure in python. Each element in the sequence is assigned a serial number, that is, the position of the element. , which also becomes an index. Similar to "array". There are 6 built-in sequences in python, namely lists, tuples, strings, Unicode strings, buffer objects and xrange objects.

1. All sequences in python can perform some specific operations, including indexing (indexing), slicing (slicing), sequence addition (adding), multiplication (multiplying), membership, length, minimum and maximum values.

2. Index

(1) Each element in the sequence is assigned a number, representing its position (index) in the sequence, the first index is 0, the second index is 1, and so on, starting from 0 and increasing, you can pass The numbers are used to access the elements of the sequence respectively.

(2) From left to right, it is incremented from 0, that is, a[0], a[1].... From right to left, the index value of the rightmost element is -1, decreasing from right to left.

3. Sharding

(1) The index is used to access a single element. Using sharding, you can access elements within a certain range. The sharding is implemented by colons, that is, a[1:3]. The implementation of the sharding operation needs to provide two indexes as boundaries, the elements of the first index are included in the shard, and the elements of the second index are not included in the shard, similar to a≤x<b.

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324689981&siteId=291194637