Python Basic Tutorials summarize the list of elements and tuples

Source: Internet
Author: User

1. Sequence

Python contains 6 built-in sequences- lists, tuples, strings, Unicode strings, buffer objects, xrange objects

2. General sequence operation

2.1 Index

Note: input () transforms the corresponding type according to the user input, and if you want to enter characters and strings, you must enclose them in quotation marks.

Raw_input () is converted into a character type regardless of the type of user input.

2.2 Shards

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

(1) numbers[:]

[1, 2, 3, 4, 5, 6, 7, 8, 9, ten] #整个列表

(2) Numbers[3:5]

[4, 5] #包括起始索引对应的元素, but excluding elements corresponding to the index

(3) numbers[-5:-3]

[6, 7] #注意索引的顺序

(4) numbers[3,3]

[] #空列表

(5) numbers[-5, 9]

[6, 7, 8, 9] #混合正负索引

(6) numbers[-20, 20]

[1, 2, 3, 4, 5, 6, 7, 8, 9, ten] #好像不存在index out of range issues

(7) Numbers[8,-8]

[] #索引区间为空

2.3 Sequence Addition

Note: Two sequences of the same type can be added

2.4 Multiplication

2.5 Membership: In

2.6 Length, min and Max values

Len ()--Returns the number of elements contained in the sequence

Min ()-the largest element in a sequence

Max ()-the smallest element in a sequence

3. List

4. Tuples

Python Basic Tutorials summarize the list of elements and tuples

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.