About python list initialization

A Python list (array) with any value/number of elements I wanted to learn about initialization using initialization , but I'm suddenly discussing initialization in the topic "Initialization with arbitrary values ​​and number of elements".

l = [0] * 10
print (l)
# [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Just increasing the number of elements of 0 does not tell where this is initialization.
What is the notion of python list initialization or python comprehension initialization?

I'd be happy if you could tell me if you know.

  • Answer # 1

    Also on that site


    As mentioned above, Python lists can dynamically add and delete elements, so there are few situations where initialization is necessary, but all elements are filled with arbitrary values. If you want to create a list, use the * operator:


    Initializing Python list (array) with arbitrary value and number of elements | note.nkmk.me

    As described in

    . To be clear, it's not much more than that.

    It doesn't mean that there is a clear concept of initialization in the first place, it creates a variable or container that has an appropriate value before processing, or fills it with an appropriate initial value after writing (writing and language However, there is no need to "study about initialization" in the first place (or it is impossible). .

  • Answer # 2

    What do you write when the title "Create a 10-element array and initialize all elements to 0" is given?

    Comprehensions can be used to write a list or dictionary data concisely.
    If you don't use comprehensions, you must create an empty list or dictionary and then add it by looping one element at a time.

    L = []
    for i in range (10): L.append (0)

  • Answer # 3

    How Python works | Python Tutorial for beginners |

    Link: https://youtu.be/zEPqqczgCEY