0

Why does this

list(('a', 'b', 'c')).extend([1, 2, 3])

evaluate to 'None'. What I mean is that the result of a constructor should be a list, so there should be no problem "extending" it, just like if I would've assigned the result of the constructor to a variable and then extended, still the result is almost always a None. So why does this happen.

vaultah
  • 44,105
  • 12
  • 114
  • 143
Apurva Kunkulol
  • 445
  • 4
  • 17

1 Answers1

-1

L = list(('a', 'b', 'c')) will create a list and assign it to the variable L. Similarly, list(('a', 'b', 'c')) will create a new list.

L.extend([1,2,3]) will perform an operation on L, with a return value of None.

So what's happening in your case is that the constructor creates a list, on which you call extend. Since extend has a return value of None, list(('a', 'b', 'c')).extend([1, 2, 3]) evaluates to None. Since the list you constructed (namely list(('a', 'b', 'c'))) wasn't assigned to a variable, there are no references to it, and python's refcounting garbage collector just sweeps up that list after the call to extend, which returns None

inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241