Categories
Python Answers

How to create list of single item repeated N times with Python?

Spread the love

Sometimes, we want to create list of single item repeated N times with Python.

In this article, we’ll look at how to create list of single item repeated N times with Python.

How to create list of single item repeated N times with Python?

To create list of single item repeated N times with Python, we can use the * operator.

For instance, we write

l = [5] * 4

to create the list l with 4 5’s in it.

Conclusion

To create list of single item repeated N times with Python, we can use the * operator.

By John Au-Yeung

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

Leave a Reply

Your email address will not be published. Required fields are marked *