Jupyter notebook - 打印 [list] 时语法无效

Jupyter notebook - invalid syntax when printing [list]

我是新来的,这可能是一个非常愚蠢的问题,但我才刚刚开始学习 python 并且在 jupyter notebook 中打印时遇到了问题。例如:

def greatest(list):
    biggest = 0
    for i in list:
        if e > biggest:
            biggest = i 
    return biggest 

那我试试:

print greatest([4,23,1])

并且错误消息指出 syntax error:invalid 语法,同时指向打印命令中 'greatest' 和 ([4,23,1]) 之间的区域。这一直是我尝试打印类似内容的所有时间,总是带有数字列表。我能做什么?

请看下面我的代码。我更正了一些内容,已将其包含在代码注释中

def greatest(numbers):  # Renamed list to numbers, since list is reserved
    biggest = 0
    for i in numbers:
        if i > biggest:   # e here should be i
            biggest = i 
    return biggest 

print(greatest([4,23,1]))  # We need brackets around what we are printing since this is py3

只需将 max(list) 用作:

 l =  [4,23,1]
 print max(l)

输出:

 23