-2

I know the use of list() is to convert a iterable to list. But a bit confused what to use while creating a new empty list.

num1 = mydict.get('num1', []) # example1
num1 = mydict.get('num1', list()) # example2

Here what is different between example1 & example2?

Vikram Ray
  • 960
  • 2
  • 10
  • 17
  • 1
    I think this is almost asking which one to use between `0` and `int()`. I believe almost no one would use the latter, but I don't understand why so many people hesitate between `[]` and `list()`. – Mechanic Pig Aug 28 '23 at 07:49

0 Answers0