2

I'm new to python and I've seen two different ways to initialize an empty list:

# way 1    
empty_list = []

# way 2
other_empty_list = list()

Is there a "preferred" way to do it? Maybe one way is better for certain conditions than the other?

Thank you

Dan.py
  • 83
  • 7

3 Answers3

2

[] is the pythonic way.
[] way is quite efficient as you can see from below image. enter image description here

-1

No there isn't much of a difference, you can neglect the difference and pick anyone of them

As most of the times it's a one or limited execution any difference in execution won't have much impact

-3

Using parenthesis will create a tuple, which is immutable. A list uses brackets.

donnieth65
  • 23
  • 4