Share Python String Learning Summary

Source: Internet
Author: User
Indexes and Shards:

1. Index: s[j] Gets the element with a specific offset

Note: Offsets have positive and negative offsets

Negative offsets are counted in reverse from the last or the right.

The negative index number plus the length of the string equals the position of the positive offset

2, the common method of sharding:

S[I:J] means, starting from the element I position, to the end of J position, which does not include the first J element (left closed right open)

S[1:] Gets all elements from the beginning of the offset to 1, including the 1 position

S[:3] Gets the element that starts with a 0 offset to an offset of 3, not including the 3 position

S[:-1] Gets all elements that begin with a 0 offset, not including the last element

s[:] Copy entire string

3, Extended shard, third limit value:

python2.3, the Shard expression adds an optional third index, which is used as a stepping

S[x:y:z] means, starting from the X position, to the position element with the offset Y (excluding the Y position), where the element with the interval Z is taken out

4. Shard Object Slice ()

>>>s = ' spam '

>>>s[1:3]

>>> ' Pa '

>>>s[slice (1,3)]

>>> ' Pa '

5, the role of sharding:

(1) A Shard expression can return a list of all elements except the first one

(2) Clean up the contents of the input file

Related Article

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.