Empty array in Python

If you want to create an empty array (or list because there are no arrays in Python), you can use this line of code:

After you do this, you can append elements to this list.

If you want to create an equivalent of an array from the C/C++ language, you can declare an array as None and multiply it by the number of values.

Let’s see, how Python treats this declaration. Let’s run this code:

This is the result:

[None, None, None, None]

You have a list with 4 None values. You can assign a new value to each element by specifying an index of the array.

Run the code.

[None, 5, None, 'z']

Notice that two values changed, at positions 0 and 2.