Python Learning 2

Source: Internet
Author: User

    • Compared with list, Dict has the following features:
    1. The speed of finding and inserting is very fast and will not slow with the increase of key;
    2. It takes a lot of memory, and it wastes a lot of memory.

And the list is the opposite:

    1. The time to find and insert increases as the element increases;
    2. Small footprint and little wasted memory.

So, Dict is a way of exchanging space for time.

Dict can be used in many places where high-speed lookups are needed, almost everywhere in Python code, it is important to use dict correctly, and the first thing to keep in mind is that the Dict key must be an immutable object .

    • Set to create a set, you need to provide a list as an input collection
    s = set([1, 1, 2, 2, 3, 3])
    s.add(key) s.remove(key)
set可以看成数学意义上的无序和无重复元素的集合,因此,两个set可以做数学意义上的交集、并集等操作:
交集& 并集|

Dictionary

d={' key ': value, ' key ': Value ...}

d[' key ']

Set

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

S=set ([1,1,1,2,3,...])

S.add (Element)

S.remove (...)

List

#感觉更像是数组, variable-length arrays

list=[' element1 ', ' Ele2 ',...] Can Countdown List[-1] ...

tuple= (' ele_1 ', ' ele_2 ',...)

Built-in function hex (number)

#转换为十六进制数

Python Learning 2

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.