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!
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:
- Check if List of Lists is Empty in Python
- Convert List from Character String to Integer in Python
- Check If Key Exists in List of Dictionaries in Python
- Access Dictionary within List in Python
- Python Programming Tutorials
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.
Statistics Globe Newsletter