在python中,将变量设置为“None”是否更容易记住?

2024-05-20 03:14:04 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个简单的问题,但由于我没有找到任何答案,我想答案是否定的。不过,为了确保这一点,我想问:

在函数中处理完变量后,将变量设置为None是否会提高python代码的效率?

例如:

def foo(fname):
    temp_1, temp_2 = load_file_data(fname)

    # do some processing on temp_1, temp_2

    temp_1 = None
    temp_2 = None

    # continue with the rest of the function

如果我们在函数末尾这样做,答案会改变吗(因为我假设python本身会在那个时候这样做)?


Tags: the函数答案代码nonedatafoodef