What is a python dictionary? How do I create and use a python dictionary?

Source: Internet
Author: User
In this article, we'll look at the dictionaries in Python, and in this article I'll explain what the Python dictionary is . and explain how the python dictionary is used . Well, don't say much nonsense, let's get into the article.

What is a python dictionary?

A dictionary is another mutable container model and can store any type of object.

Each key value of the dictionary is key=>value with a colon : split, with a comma, split between each key-value pair, and the entire dictionary is enclosed in curly braces {}, as shown in the following format:

D = {key1:value1, key2:value2}

The key is generally unique, and the value does not need to be unique if the last key value pair is repeated instead of the previous one.

>>>dict = {' A ': 1, ' B ': 2, ' B ': ' 3 '};>>> dict[' B '] ' 3 ' >>> dict{' a ': 1, ' B ': ' 3 '}

The value can take any data type, but the key must be immutable, such as a string, a number, or a tuple.

How does the Python dictionary work?

A simple Dictionary instance:

Dict = {' Alice ': ' 2341 ', ' Beth ': ' 9102 ', ' Cecil ': ' 3258 '}

You can also create a dictionary like this:

Dict1 = {' abc ': 456};d ict2 = {' abc ': 123, 98.6:37};
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.