List basics #1

Tech-joho TOP > Python exercises > List basics #1 <

Problem

Create a list that contains ten numbers from 1 to 10, and assign it to a variable my_list

Write answer to the black text area below, and click “Submit”. An example answer will be displayed.

Example of execution results

This program shows noting, but if you run the answer program, and “print(my_list)”, the numbers below will be show.
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 

Example answer

This is an example answer.

my_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Another example is here.

my_list = list(range(0,10))

Explanation

To create a list, write “[” and “]” first, and write list items between them, separate them with “,” (comma).

You can create a list of numbers of certain range using the range function and convert its’result to a list.

my_range_list = list(range(5, 10))
print(my_range_list)

The basics of list of Python is explained in the linked page below.

Collection of many item