Python基础-dict字典

来源:互联网 发布:知微科技 上市了吗 编辑:程序博客网 时间:2024/05/02 13:32
#!usr/bin/env/ python 
#coding:utf-8


#dict字典


items = [('name','lichanglin'),('age',24)]
print(items)


print(dict(items))


dict1 = dict(name = 'wangwang',age = 42)
print(dict1)


#字典的格式化字符串
phone = {}
phone['benth'] = '3342'
phone['alex'] = '4456'
phone['wlad'] = '4567'
print(phone)


x = {'wlad':'3467'}
print('benth\'s phone number is %(benth)s.'%phone)




#字典方法:clear/copy/get/has_key/items/keys/pop/popitem/update/values
print(phone.get('benth'))
print(phone.get('sdfg'))
print(phone.keys())
print(phone.values())
print(phone.items())
phone2 = phone.copy()
print(phone2)
print(phone.pop('wlad'))
print(phone)
print(phone.popitem())
print(phone)


#phone2 = phone.copy()
print(phone.update(x))
print(phone)
0 0
原创粉丝点击