0
我是初学者在Python和通过学习Python的艰难的方式学习。找不到在我的代码中的错误的原因python
不幸的是,我不断收到一个错误,不知道为什么。
下面的代码:
def new(num_buckets=256): # Creates list aMap and fills it with 256 empty lists.
""" Initializes a Map with the given number of buckets."""
aMap = []
for i in range(0, num_buckets):
aMap.append([])
return aMap
new()
print aMap
奇怪的是我不断收到一条消息说,阿马帕,没有定义,即使我只是跑一个函数创建它作为一堆名单内空水桶中。
感谢您的帮助。
呃..但不是'aMap'仅定义,因此范围的你'new'功能里面?你想做'print(new())'吗?或'temp = new()print(temp)'? – EdChum 2014-08-28 20:15:26
我觉得你不太明白'return'的作用,以及变量的作用范围。 – Blorgbeard 2014-08-28 20:16:30
你需要处理返回变量。你可以做result = new()然后打印结果; – TheOneWhoPrograms 2014-08-28 20:16:33