Magic Of * In Python

In this article I’ll explain about many different ways, we can use * a.k.a. asterisk in Python.

Photo by Rakicevic Nenad at pexels

Let’s get started.

Create Collection With Repeated Elements

Using * operator we can duplicate the elements as many times as we want. Below is the example code where every element is added 3 times:

lst = [4,3,5] * 3
print(lst)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store