Python sixth day (string-index and Shard)

Source: Internet
Author: User

Indexes and Shards


>>> Wu = ' wuang '

>>> Wu[0]

' W '

>>> Wu[1]

' U '

>>> wu[1:]

' Uang '

>>> Wu[1:3]

' UA '

>>> Wu[-1]

' G '

>>> Wu[:-1]

' Wuan '

Index: Wu[i]

The first element has an offset of 0

[0]: first element

[-1]: last element

Shard Wu[i:j]

Upper boundary (i) does not contain


If I is not given, the default is 0

Wu[1:3]

Wu[:3]

WU[:-1]

wu[:]


Shards also have a limit value

Called Stepping

WU[I:J:K]

Offset to I until j-i, indexed once per k element

Wu[1:4:2]

The result is

>>> Wu[1:4:2]

' UN '

Every 2, i.e.

Wuang

U n

WU[::-1]

Step-in effect

Indicates that the Shard is right-to-left instead of left-to-right

A negative step is equivalent to a two-border reciprocal exchange

>>> Wu[::-1]

' Gnauw '



>>> ' Wuang ' [1:4]

' Uan '

>>> ' Wuang ' [Slice (1,4)]

' Uan '

>>> ' Wuang ' [::-1]

' Gnauw '

>>> ' Wuang ' [Slice (none,none,-1)]

' Gnauw '


This article is from the "Don't Ang" blog, please be sure to keep this source http://wuang.blog.51cto.com/9559762/1606442

Python sixth day (string-index and Shard)

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.