In this article we will discuss how to create a list and initialise with same values.

Creating a list of same values by [] and multiply

Suppose we want to create a list of strings, which contains 20 same strings i.e. ‘Hi’

Let’s see how to do that i.e.

[‘Hi’] will create a list with single value, then we can multiply this list by 20. It will repeat the contents of list 20 times.
So, lists content will be now i.e.

Creating a list of same values by List Comprehension with range()

This is an another way to create a list of same value using range() i.e.

In this list comprehension, for loop will iterate over the range object 20 times and in each iteration it will add ‘Hi’ in the list.
So, list will coatain 20 ‘Hi’ elements i.e.

Complete example is as follows,



Click Here to Subscribe for more Articles / Tutorials like this.