Python's re-learning----A simple dictionary

Source: Internet
Author: User

# filename:python2.25 (2). py
# Author:super
# date:2018-2-25

Print (' Today to learn the Zidian ')

# in Python, dictionaries are a series of key-value pairs that each have a value to correspond to, and you can use keys to access the corresponding values
# The value associated with the key can be a number, a string, a list, or a dictionary
# get the value by accessing the key [' Color ']
Alien = {' Color ': ' green ', ' Points ': 5}
Print (alien[' color ')
Print (alien[' points ')
# You can add this value to the dictionary directly using the dictionary [' key ']= value method
alien[' x-position '] = 0
alien[' y-position '] = 25
Print (alien)
# You can use the Del method to permanently delete this key value
Del alien[' points ']
Print (alien)

user = {
' AA ': 11,
' DD ': 12,
' CC ': 13,
' BB ': 11,
}
# through key, the method of value can be traversed in. Items ()
For key, value in User.items ():
Print (key, value)

# Traverse Key
For I in User.keys ():
Print (i)
# Traverse Value
For I in User.values ():
Print (i)
# Traverse a sorted key
For I in Sorted (User.keys ()):
Print (i)
# by set, you can remove duplicate values in value
For I in Set (User.values ()):
Print (i)

Aliens = []

For I in range (1, 3):
New_alien = {' Color ': ' Yellow ', ' Points ': 5}
Aliens.append (Aliens)
Print (Aliens)

Python's re-learning----A simple 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.