+ 2
print del()
a=[1,2,3] print (del a[0]) output: error a=[1,2,3] del a[0] print (a) output: [2,3] why in first case it gives error?
4 RĂ©ponses
+ 3
Like Steppenwolf said it doesn't return a value del is a statement and most statements in Python don't return anything. Del is used to decrease the reference count by 1 basically 'hiding' the variable from current scope.
+ 2
del does not return any value
+ 2
tardigrade
Exactly, because there is nothing to print. I'm not sure about that, because I'm begginer at Python as well, but google says del does not return any value. And that seems to be logical for me.
+ 1
Does it mean that del can't be with print? in the same line?