Python 3 Grammar Note (5): Dictionary

Source: Internet
Author: User

As you can see from the previous sections, Python is the most basic type of programming language.

    • List
    • Tuple
    • Set
    • Dict

It can be seen that the granularity of segmentation in data structure is to satisfy the need of more domain programming.

1 Creating a dictionary

Other methods, such as list and tuple, can also be created, see the manual. The keys of a dictionary are non-repeatable and are somewhat similar in nature to the set of set,dict that can be understood as carrying values. Of course Dict does not have a set operation method (intersection, set, difference set, etc.).

2 Reading and writing dictionaries

a_dict[' database ' = ' blog '            #database键如不存在表示增加, exists is to change the value

Reading a nonexistent key throws a Keyerror exception.

3 except for strings, read-only types can be used as keys to dictionaries

suffixes = {: [' KB ', ' MB ', ' GB ', ' TB ', ' PB ', ' EB ', ' ZB ', ' YB '],            1024x768: [' KiB ', ' MiB ', ' GiB ', ' TiB ', ' PiB ', ' EiB ', ' ZiB ', ' Yib ']}

4 Boolean Test

{} indicates false, non {} indicates true

5 None

Like other languages, NULL, which belongs to the Nonetype type, has only one value.

At the Boolean test plane none is False,not none is true.

Python 3 Grammar Note (5): Dictionary

Related Article

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.