Python 我得到了这个简单代码的语法错误
我试着做字典操作:Python 我得到了这个简单代码的语法错误,python,Python,我试着做字典操作: mathematics=['Geoffrey Hinton':78,'Andrew Ng':95,'Sebastian Raschka':65,'Yoshua Benjio':50,'Hilary Mason':70,'Corinna Cortes':66,'Peter Warden':75] 这给了我一个无效的语法错误。您得到这个错误是因为您使用的是列表,也不是字典。将其更改为: mathematics={'Geoffrey Hinton':78,'Andrew Ng':
mathematics=['Geoffrey Hinton':78,'Andrew Ng':95,'Sebastian Raschka':65,'Yoshua Benjio':50,'Hilary Mason':70,'Corinna Cortes':66,'Peter Warden':75]
这给了我一个无效的语法错误。您得到这个错误是因为您使用的是列表,也不是字典。将其更改为:
mathematics={'Geoffrey Hinton':78,'Andrew Ng':95,'Sebastian Raschka':65,'Yoshua Benjio':50,'Hilary Mason':70,'Corinna Cortes':66,'Peter Warden':75}
如果你仔细看,你会看到花括号,这是一本字典。Dicts存储键值对,而您以前使用的(list)只存储值。对于字典使用大括号
{}
,对于列表使用方括号[]
。请阅读