Python data structure

Source: Internet
Author: User

The following is a reading note from Python tutorial:

I. Operations on the list

The difference between the remove,pop of 1.list and clear

List.remove (x): Removes an element with a list value from the list

List.pop ([i]): Removes the first element from the list, and if I is not specified, the last element is deleted.

List.clear (): Remove all elements from list

2. List-derived

We usually create a list from a sequence in the following way:

result = [] for in range:    result.append (x)

The downside of using the above approach is that the variable I still exists after the loop, which we do not want to see, in order to avoid this waste of space, we use the following two ways:

  for in range[map(Lambda i:i, range (10

The difference between 3.list and tuple

Both list and tuple are sequences of this type, but the list is mutable and the tuple is immutable. And the data types in the list are usually consistent, and the data types in the tuple are usually inconsistent.

Python data structure

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.