How to Create a List of Multiples in Python

In today’s tutorial, we’ll be learning how to create a list of multiples in Python. Python, as a high-level and general-purpose programming language, allows us to perform such tasks quite easily.

This can be incredibly useful when you want to create a list of a certain size that contains multiples of a specific number.

Step 1: Define the Number and the Size of the List

The first thing you need to do is define the number of which you want to find multiples. Additionally, you also need to state how many multiples you want to find. This will be the size of your list.

Here, we have decided to find the first 10 multiples of 5.

Step 2: Generate the List of Multiples using a For Loop

Next, we will generate the multiples. To generate the numbers, we use list comprehension, which is a compact way of creating a new list by performing some operation on each item in an existing list.

Furthermore, we will use a for loop where the loop variable ranges from 1 to the desired number of multiples.

Step 3: Print the List of Multiples

Finally, we print out our list of multiples:

The Complete Code:

After each of the steps, the complete code for creating a list of multiples in Python will look like this:

Output:

The generated output would be as follows:

[5, 10, 15, 20, 25, 30, 35, 40, 45, 50]

Conclusion

As you can see, creating a list of multiples in Python is a rather straightforward process when you’re familiar with loops and list comprehension. This technique can be quite useful in a variety of scenarios, especially in mathematical problems and algorithms.