print(key,aDict[key])相当于名字和内容
#print语句默认每行添加一个换行符,所以:
>>> a={'host':'earth'} >>> a['port']=80 >>> a {'host': 'earth', 'port': 80} >>> a('port')=80 SyntaxError: can't assign to function call >>> a{'port'}=80 SyntaxError: invalid syntax >>> a['port']=80 >>> a {'host': 'earth', 'port': 80} >>> a.keys() dict_keys(['host', 'port']) >>> a keys() SyntaxError: invalid syntax >>> keys() Traceback (most recent call last): File "<pyshell#158>", line 1, in <module> keys() NameError: name 'keys' is not defined >>> a.keys( ) dict_keys(['host', 'port']) >>> a.key() Traceback (most recent call last): File "<pyshell#160>", line 1, in <module> a.key() AttributeError: 'dict' object has no attribute 'key' >>>