Why is del here?

Asked 2 years ago, Updated 2 years ago, 115 views

I don't know why there is a separate del

Rather than clearing the variable, you can just assign None, and in the list, pop() and remove() are separate when erasing elements.

Why did they make del for us? Or is it because del plays a role like garbage collection?

python del

2022-09-21 19:43

1 Answers

The Python Language Reference shows what del does.

Deletion of a name removes the binding of that name from the local or global namespace

Deling a name does the job of erasing the binding of this name on the local/global namespace

Assigning None, on the other hand, does not eliminate binding.

I think it has the advantage of being able to limit the scope of a variable, but I don't know why it's useful in Python.


2022-09-21 19:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.