I want a list full of the same thing, where the thing will either be a string or a number. Is there a difference in the way these two list are created? Is there anything hidden that I should probably know about?
list_1 = [0] * 10
list_2 = [0 for i in range(10)]
Are there any better ways to do this same task?
Thanks in advance.
It depends on whether your list elements are mutable, if they are, there’ll be a difference:
For immutable elements, the behavior of the two is the same. There might be a performance difference between them, but I’m not sure which one would perform faster.