2024-06-26 02:39:18 发布
网友
def __init__(self, specfile, listfile): self.spec=AssignmentSpec(specfile) self.submissions={}
我不明白这个的意思,请帮忙,{}里面什么都没有??你知道吗
{}
它定义了dict类型的对象。如果您来自C#/Java背景,则与以下内容相同:
IDictionary<xxx> myDict = new Dictionary();
或者
Map<xxx, yyy> myMap = new HashMap<xxx, yyy> ();
或C++(松散地,因为地图主要是树):
map<xxx, yyy> myMap;
xxx和yyy因为python是非类型化语言。你知道吗
意思是这是一本空字典。你知道吗
在python中:
{} means empty dictionary.[] means empty list.() means empty tuple.
{} means empty dictionary.
[] means empty list.
() means empty tuple.
示例:
print type({}), type([]), type(())
输出
<type 'dict'> <type 'list'> <type 'tuple'>
编辑:
正如Paco在评论中指出的,(1)将被认为是一个用括号括起来的数字。要创建一个只有一个元素的元组,必须在末尾包含逗号,如(1,)
(1)
(1,)
print type({}), type([]), type((1)), type((1,)) <type 'dict'> <type 'list'> <type 'int'> <type 'tuple'>
这是定义词典的字面方法。在这种情况下,它是一本空字典。与self.submissions = dict()相同
self.submissions = dict()
>>> i = {} >>> z = {'key': 42} >>> q = dict() >>> i == q True >>> d = dict() >>> d['key'] = 42 >>> d == z True
它定义了dict类型的对象。如果您来自C#/Java背景,则与以下内容相同:
或者
或C++(松散地,因为地图主要是树):
xxx和yyy因为python是非类型化语言。你知道吗
意思是这是一本空字典。你知道吗
在python中:
示例:
输出
编辑:
正如Paco在评论中指出的,
(1)
将被认为是一个用括号括起来的数字。要创建一个只有一个元素的元组,必须在末尾包含逗号,如(1,)
这是定义词典的字面方法。在这种情况下,它是一本空字典。与
self.submissions = dict()
相同相关问题 更多 >
编程相关推荐