Python 字典 Print 格式化

__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"]

 

posted on 2013-08-05 16:49  雨渐渐  阅读(634)  评论(0编辑  收藏  举报

导航