+ 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?

1st Aug 2018, 8:29 AM
tardigrade
tardigrade - avatar
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.
1st Aug 2018, 9:16 AM
TurtleShell
TurtleShell - avatar
+ 2
del does not return any value
1st Aug 2018, 8:34 AM
Steppenwolf
Steppenwolf - avatar
+ 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.
1st Aug 2018, 8:40 AM
Steppenwolf
Steppenwolf - avatar
+ 1
Does it mean that del can't be with print? in the same line?
1st Aug 2018, 8:37 AM
tardigrade
tardigrade - avatar