Skip to main content
 首页 » 编程设计

python之获取 'TypeError: ' 列表'对象不可调用'错误

2024年10月24日15yjmyzz

<分区>

在下面的自定义函数中:

def get_a_random_memory(length, lower_sum_range, upper_sum_range): 
 
    memory = list() 
 
 
    for i in range(0, length): 
        memory.append((2 * random.randint(0, 1) - 1)) 
 
 
    sum = 0 
    for i in range(0, length): 
        if len(memory) == 0: 
            sum = memory[i] 
        else: 
            sum = sum + memory[i] 

我收到以下错误。

>>> print memories.get_a_random_memory(10, 1, 10) 
Traceback (most recent call last): 
  File "<input>", line 1, in <module> 
  File "C:\Users\omarshehab\PycharmProjects\practice\memories.py", line 28, in get_a_random_memory 
    if len(memory) == 0: 
TypeError: 'list' object is not callable 

我假设我正在正确访问列表变量内存。

有什么帮助吗?