Divide List Elements by Float in Python (Example)

In this tutorial, you’ll learn how to divide each element of a list by a floating-point number in the Python programming language.

The table of contents is structured as follows:

Let’s dive into it!

Example

Sometimes, you may need to divide each element of a list by a floating-point number in Python. This operation is useful when you want to scale or normalize the values in the list based on a specific factor.

To divide each element of a list by a float in Python, you can follow these steps:

Step 1: Declare the list.

Step 2: Define the float value.

Step 3: Divide each element by the float value.

Here’s an example of dividing list elements by a float:

# Step 1: Declare the list
my_list = [10, 20, 30, 40, 50]
 
# Step 2: Define the float value
divisor = 2.5
 
# Step 3: Divide each element by the float value
for i in range(len(my_list)):
    my_list[i] /= divisor
 
# Print the updated list
print(my_list)  # Output: [4.0, 8.0, 12.0, 16.0, 20.0]

In the above example, we have a list named my_list containing integer values. We defined a float value divisor as 2.5. Then, using a for loop, we divided each element of the list by the float value. Finally, we printed the updated list.

Video, Further Resources & Summary

Do you need more explanations on dividing list elements by a float in Python? Then you should have a look at the following YouTube video of the Statistics Globe YouTube channel.

The YouTube video will be added soon.

Furthermore, you could have a look at some of the other tutorials on Statistics Globe:

This post has shown how to divide each element of a list by a float in Python. In case you have further questions, you may leave a comment below.

 

Ömer Ekiz Informatics Expert

This page was created in collaboration with Ömer Ekiz. You may have a look at Ömer’s author page to read more about his academic background and the other articles he has written for Statistics Globe.

 

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.

The maximum upload file size: 2 MB. You can upload: image. Drop file here

Top