Python[八]:Dictionaries

Dictionaries >>> tel={'Jack':4098,'Tom':4139} >>> tel['Marry']=4555 >>> TEL Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> TEL NameError: name 'TEL' is not defined >>> tel {'Marry': 4555, 'Jack': 4098, 'Tom': 4139} >>> tel['Marry'] 4555 >>> tel['irv']=454 >>> tel {'Marry': 4555, 'Jack': 4098, 'irv': 454, 'Tom': 4139} >>> del tel['Marry'] >>> tel {'Jack': 4098, 'irv': 454, 'Tom': 4139} >>> list(del.keys()) SyntaxError: invalid syntax (<pyshell#9>, line 1) >>> list(tel.keys()) ['Jack', 'irv', 'Tom'] >>> 'Marry' in tel False >>> 'Tom' in tel True >>> dict([('sape':123),('guido':415),('jack':4298)]) SyntaxError: invalid syntax (<pyshell#13>, line 1) >>> dict([('sape',1230),('jack',563),('guido',45)]) {'sape': 1230, 'jack': 563, 'guido': 45} >>> {x:x**2 for x in (2,4,6)} {2: 4, 4: 16, 6: 36} >>> dict(sape=4563,guido=45454,jack=4545) {'sape': 4563, 'jack': 4545, 'guido': 45454} >>> 

你可能感兴趣的:(python,list,Module,File)