What is the output of the following? “`python class MyList(list): def append(self, item): super().append(item * 2) m = MyList() m.append(3) m.extend([4, 5]) print(m) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python class MyList(list): def append(self, item): super().append(item * 2) m = MyList() m.append(3) m.extend([4, 5]) print(m) “`

Key points

  • Custom `append` method in `MyList` class multiplies input by 2
  • `append` adds 6 to the list first, then extends [4, 5]
  • Output is [6, 4, 5]

Ready to go further?

Related questions