004 dictionary,

Source: Internet
Author: User

004 dictionary,

Ing type

# Definition

Integer type will create a new space in the memory
Dic = {[2, 3]: 'alow', 'age': 35, 'hobby': 'meizi', 'is _ handsome': True,} # The variable value cannot be a key.

Use braces to create and use more
Create with dict ()
Dic2 = dict ('name', 'Alex '),))

# Add a key
Dic. setdefault ('airen', 'clear ')
If yes, no value is added. If no value is added, all values are returned.

# Query
Dic. keys ()
View All keys and store a keys type, not a list. You can convert them to a list.
Dic. values () view value
Dic. items ()

# Change
Dic2 = {'1': '123 '}
Dic. update (dic2)
If the same key exists, it will overwrite

# Delete
Dic. clear ()
Del dic ['name']
A = dic. pop ('name ')

# Dictionary nesting # Picture content is purely funny

The dictionary has more keys.

# Sorting
Print (sorted (dic. values ()))

# Traversal
For I indic:
Print (I, dic [I], end = '')

# String to list
Str = '1, 2, 3'
Arr = str. split (',')

 

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.