Categories
Python Answers

How to create an empty list in Python with certain size?

Spread the love

To create an empty list in Python with certain size, we can use the * operator.

For instance, we write:

l = [None] * 10
print(l)

We create a list with 10 None entries with [None] * 10.

Therefore, l is [None, None, None, None, None, None, None, None, None, None].

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.