Python 字典的使用

#!/usr/bin/python

ab={    'jack'  :   'jack@1.com',
        'ken'   :   'ken@1.com',
        'hellen'    :   'hellen@1.com'
    }
print 'jack address is %s' % ab['jack']

ab['sten']='sten@1.com'
del ab['ken']
print '\nTHere are %d conntacts in the address-book\n' % len(ab)
for name,address in ab.items():
    print 'Contact %s at %s' % (name,address)
if 'sten' in ab:
    print 'yes\n'
else:
    print 'No\n'

 

posted @ 2013-03-05 16:39  墨迹哥's  阅读(165)  评论(0编辑  收藏  举报