def __init__(self, specfile, listfile):
self.spec=AssignmentSpec(specfile)
self.submissions={}我不明白这是什么意思,请帮帮忙,{}里面什么都没有??
发布于 2013-09-24 17:34:17
这是字面上定义字典的方式。在这种情况下,它是一个空字典。它与self.submissions = dict()相同
>>> i = {}
>>> z = {'key': 42}
>>> q = dict()
>>> i == q
True
>>> d = dict()
>>> d['key'] = 42
>>> d == z
True发布于 2013-09-24 17:34:15
这意味着它是一本空字典。
在python中:
{}表示空字典。
[]表示空列表。
()表示空的元组。
示例:
print type({}), type([]), type(())输出
<type 'dict'> <type 'list'> <type 'tuple'>编辑:
正如Paco在评论中指出的那样,(1)将被认为是一个用括号括起来的数字。要创建一个只有一个元素的元组,必须在末尾包含一个逗号,就像这样,(1,)
print type({}), type([]), type((1)), type((1,))
<type 'dict'> <type 'list'> <type 'int'> <type 'tuple'>发布于 2013-09-24 17:41:00
它定义了一个dict类型的对象。如果您来自C#/Java背景,则与以下内容相同:
IDictionary<xxx> myDict = new Dictionary();或
Map<xxx, yyy> myMap = new HashMap<xxx, yyy> ();或者在C++中(松散地说,因为map主要是一棵树):
map<xxx, yyy> myMap;xxx和yyy因为python是一种非类型化语言。
https://stackoverflow.com/questions/18977813
复制相似问题