List and Ganso of the Python series

Source: Internet
Author: User

Container:

List and Ganso

Difference:

The list can be modified, and the meta-ancestor cannot

Sequence: List, Ganso (each element in the sequence has its own ID (number), numbering starts from 0 to the right)

Common:

Index:

Eg:name= ' Jack ', name[0]= ' J '

Note: You can also direct ' Jack ' [0]= ' J '

Sharding:

Provides two indexes as a boundary, the element of the first index is contained within the Shard, and the second is not contained within the Shard.

eg:numbers=[0,1,2,3,4,5,6,7,8,9], then numbers[0:3]=[0,1,2]

Shortcut: numbers[:] is equal to the entire sequence

Step: eg:numbers[0:5:2]=[0,2,4], where the step size is set to 2

Note: For a positive step, Python extracts the element to the right from the head of the sequence until the last element, and for a negative step, the

The tail of the sequence begins to extract elements to the left until the first element

Addition:

Note: Only two sequences of the same type can be connected.

eg:[1,2,3]+[4,5,6] = [1,2,3,4,5,6]

' Hello, ' + ' Python ' = ' Hello,python '

error:[1,2,3]+ ' Hello ' (Error)

Multiplication:

Multiplying the number x by a sequence creates a new sequence, and in the new sequence, the original sequence is repeated x times.

eg: ' Hello ' *3= ' Hellohellohello '

Membership:

In order to check whether a value is in a sequence, you can use the In operator to return a value of true or false.

eg:permission= ' rwx '

' R ' in permission, returns True

Characteristics:

Change the list:

Eg:data = [1,1,1,1,1]

data[1]=2, this sentence changes the list, changing the list to [1,2,1,1,1]

Del Data[2], remove the 3rd element of the list, and change the list to [1,2,1,1]

Map: Dictionary (each element in the map has its own key)

Collection:


List and Ganso of the Python series

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.