# 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