Python Learning--day1 (list, tuple, dictionary differences)

Source: Internet
Author: User

1. What is the difference between a list, a tuple, a dictionary?

The ① list is the brackets [], the tuples are parentheses (), the dictionary is curly braces {}

② lists are ordered, tuples are ordered, dictionaries are unordered

The ③ list stores values, tuples are values, dictionaries are key-value pairs (key\value)

The ④ list is mutable, the tuple is immutable, and the dictionary is mutable.

On an application, tuples are compared to lists:

A. Faster than List operation

B. ' Write-protect ' of data

C. Can be used in string formatting

D. A key that can be used as a dictionary

A dictionary is a way of exchanging space for time, compared to a dictionary:

A. The search and insertion of dictionaries is very fast and does not increase with the key value

B. Dictionaries require a lot of memory, and memory waste is much

C. The lookup time of a list increases as the element increases

D. Small footprint, Little wasted memory

------Set Collection: The only difference between a ① and a dictionary is that there is no store value for the corresponding

② Create a set, you need to provide a list as an input collection

③ because set has the ability to automatically remove duplicate elements, its elements must be immutable, since it is not possible to determine whether two mutable objects are equal

Python Learning--day1 (list, tuple, dictionary differences)

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.