wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Understanding Lists in Python

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What is the correct way to create a list in Python?

a)

`list = (1, 2, 3)`

b)

`list = [1, 2, 3]`

c)

`list = {1, 2, 3}`

d)

`list = <1, 2, 3>`

2.

How can you access the third element in a list named `my_list`?

a)

`my_list[2]`

b)

`my_list[3]`

c)

`my_list[1]`

d)

`my_list[-1]`

3.

Which of the following methods is used to add an element to the end of a list in Python?

a)

`list.add()`

b)

`list.append()`

c)

`list.insert()`

d)

`list.extend()`

4.

What will be the output of the following code? ```python my_list = [1, 2, 3] my_list.append(4) print(my_list) ```

a)

`[1, 2, 3]`

b)

`[1, 2, 3, 4]`

c)

`[4, 1, 2, 3]`

d)

`[1, 2, 3, 4, 4]`

5.

How do you remove the element at index 2 from a list named `my_list`?

a)

`my_list.remove(2)`

b)

`my_list.pop(2)`

c)

`my_list.delete(2)`

d)

`my_list.clear(2)`

6.

What will be the result of the following code? ```python my_list = [10, 20, 30, 40] print(my_list[1:3]) ```

a)

`[10, 20, 30]`

b)

`[20, 30]`

c)

`[20, 30, 40]`

d)

`[30, 40]`

7.

Which of the following statements will create a list of numbers from 0 to 9?

a)

`list(range(0, 10))`

b)

`list(range(1, 10))`

c)

`list(range(0, 9))`

d)

`list(range(1, 9))`

8.

What is the output of the following code? ```python my_list = [1, 2, 3, 4, 5] print(len(my_list)) ```

a)

`4`

b)

`5`

c)

`6`

d)

`None`

9.

How can you concatenate two lists `list1` and `list2` in Python?

a)

`list1 + list2`

b)

`list1.append(list2)`

c)

`list1.extend(list2)`

d)

`list1 * list2`

10.

Which of the following methods can be used to sort a list in ascending order?

a)

`list.sort()`

b)

`list.order()`

c)

`list.arrange()`

d)

`list.organize()`

11.

What will be the output of the following code? ```python my_list = [1, 2, 3, 4, 5] my_list.reverse() print(my_list) ```

a)

`[5, 4, 3, 2, 1]`

b)

`[1, 2, 3, 4, 5]`

c)

`[1, 3, 5, 2, 4]`

d)

`[5, 3, 1, 4, 2]`

12.

How do you check if an element exists in a list?

a)

`element in list`

b)

`list.contains(element)`

c)

`list.has(element)`

d)

`element.exists(list)`

13.

What will be the output of the following code? ```python my_list = [1, 2, 3] my_list.insert(1, 4) print(my_list) ```

a)

`[1, 4, 2, 3]`

b)

`[1, 2, 3, 4]`

c)

`[4, 1, 2, 3]`

d)

`[1, 2, 4, 3]`

14.

Which of the following will create a list of squares of numbers from 0 to 4?

a)

`[x^2 for x in range(5)]`

b)

`[x**2 for x in range(5)]`

c)

`[x*2 for x in range(5)]`

d)

`[x**2 for x in range(1, 5)]`

15.

What is the result of the following code? ```python my_list = [1, 2, 3, 4, 5] print(my_list[-2]) ```

a)

`4`

b)

`5`

c)

`3`

d)

`2`