python dictionary data type 200 310

dict dictionary

understanding:

The dictionary is a container, but it is disorderly

Thinking:

Ordered collection, data serial number can be found

Unordered container, to how we can find the data it

Understand disorderly container

Life unordered containers:

The figure is a point of delivery of the stack

This is equivalent to a stacking point container object

Here Insert Picture Description

  • Think

Dump sites stored in many courier objects

How to find the desired courier?

Dictionary details

  • Dictionary defined by {}

  • A dictionary is unordered container

  • By storing key-value pairs

    • Between the key and values: partition
    • By a plurality of key-value pairs, separated
  • The only key required

  • Only key string, number, tuple type, the value may be any type

Dictionary operations

xiaoming = {"name": "小明",
            "age": 18,
            "gender": True,
            "height": 1.75}

Here Insert Picture Description

  • Dictionary definitions

  • Increased data

  • delete data

  • change the data

  • Query data

  • Code to achieve the functions described above

Dictionary traversal

Three ways to traverse the dictionary

In three cases the following example

xiaoming = {"name": "小明",
            "age": 18,
            "gender": True,
            "height": 1.75}

A way to give key

  • achieve

Second way to obtain the value

  • achieve

Third approach, both the key and value

  • achieve
Published 77 original articles · won praise 1 · views 1225

Guess you like

Origin blog.csdn.net/whalecode/article/details/104771496