__author__ = 'dell' ab = {'Swaroop': 'swaroopch@byteofpython.info', 'Larry': 'larry@wall.org', 'Matsumoto': 'matz@ruby-lang.org',
'Spammer': 'spammer@hotmail.com'} print "Swaroop's address is %s" % ab['Swaroop'] # add a key/value pair
ab['Guido'] = 'guido@python.org' del ab['Spammer'] print "\nthere is %d contacts in the address-book\n" % len(ab)
for name, address in ab.items():
print 'contact %s at %s' % (name, address) if 'Guido' in ab:
print "\n Guido's address is %s" % ab["Guido"]
相关文章
- python读取文件中的字典
- python3中格式化输出时报错unsupported format string passed to bytes.__format__
- python3 json数据格式的转换(dumps/loads的使用、dict to str/str to dict、json字符串/字典的相互转换)
- python将列表元素全部小写_python实现创建新列表和新字典,并使元素及键值对全部变成小写...
- python字典中的值只能是字符串类型_python字典key不能是可以是啥类型
- python中字典的复制
- python-字典和Json的区别
- python的print输出txt
- Python 随机列表、集合、元组、字典的生成和排序
- Python 实验五 字典与集合