Python passing list as argument

前端 未结 4 610
情书的邮戳
情书的邮戳 2020-11-27 07:08

If i were to run this code:

def function(y):
    y.append(\'yes\')
    return y

example = list()
function(example)
print(example)

Why woul

4条回答
  •  执笔经年
    2020-11-27 07:31

    Its because you called the function before printing the list. If you print the list then call the function and then print the list again, you would get an empty list followed by the appended version. Its in the order of your code.

提交回复
热议问题