Python Learning Note 0001: String slicing problem explanation __python

Source: Internet
Author: User

(1) (http://www.pythontab.com/html/2013/pythonjichu_0128/182.html)

First, analyze the slice operation from the principle:

A slice of the list, inside of which is calling the __getitem__,__setitem__,__delitem__ and slice functions. The slice function is also associated with the range () function.

The key passed to the slice is a special slice object. The object has attributes that describe the orientation of the requested slice, for example:

1 2 3 4 A = [1, 2, 3, 4, 5, 6] x = A [1:5] # x = a.__getitem__ (Slice (1, 5, None)) a [1:3] = [One,]# a.__setitem__ (Slice (1, 3, None), [one, one]) del a [1:4]# a.__delitem_ _ (Slice (1, 4, None))

Python's slicing capabilities are actually more powerful than many programmers think.

1 A = m [0:100:10] # sliced slices with stepping (step value =10)

Note: Stepping is step

When step > 0 o'clock

Slices from start (including start)

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.