Basic List Comprehensions
In this step, you will start by learning the basics of list comprehensions and how they can be used to create and manipulate lists in Python.
Now, open the ~/project/list_comprehensions.py
file and add the following code:
## list comprehensions to create a list of squared numbers
squared_numbers = [x**2 for x in range(10)]
print(squared_numbers)
Next, execute the following commands in the terminal to run the script and check the output:
python3 ~/project/list_comprehensions.py
The information below should be displayed on your terminal:
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]