Python----------indexes and shards

Source: Internet
Author: User
Index

The index in Python is from 0 the beginning, so the index 0 corresponds to the first element of the sequence 1 . To get 5 the first element, you need to use the index value 4 .

In addition to the forward index,Python introduces the use of negative index values, which are counted from the back forward, for example, -2 an index that represents the penultimate 2 element.

An error occurs when a single index is greater than or equal to the length of the string.

Sharding

Shards are used to extract the desired subsequence from a sequence, using:

var[lower:upper:step]

Its scope includes lower , but does not include upper , that [lower, upper) represents the step value interval size, if there is no default 1 .

s = ' Hello World ' s[1:3] ' el ' s[1:-2] ' ello wor ' s[:3]        ' hel ' s[-3:] ' rld ' s[::2] ' hlowrd '

When the value of step is negative, omitting lower means that the Shard begins at the end, and omitting upper means always slicing to the beginning.

S[::-1] ' Dlrow Olleh '

Python----------indexes and shards

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.