pythonbook/Python 基础教程/Collections模块.py

9 lines
308 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from collections import defaultdict
person = defaultdict(lambda : 'Key Not found') # 初始默认所有key对应的value均为Key Not Found
person['name'] = 'xiaobai'
person['age'] = 18
print ("The value of key 'name' is : ",person['name'])
print ("The value of key 'adress' is : ",person['city'])