NEW
Font size
WorksheetsUnderstanding Lists in Python
Total questions: 15
Worksheet time: 8mins
What is the correct way to create a list in Python?
`list = (1, 2, 3)`
`list = [1, 2, 3]`
`list = {1, 2, 3}`
`list = <1, 2, 3>`
How can you access the third element in a list named `my_list`?
`my_list[2]`
`my_list[3]`
`my_list[1]`
`my_list[-1]`
Which of the following methods is used to add an element to the end of a list in Python?
`list.add()`
`list.append()`
`list.insert()`
`list.extend()`
What will be the output of the following code? ```python my_list = [1, 2, 3] my_list.append(4) print(my_list) ```
`[1, 2, 3]`
`[1, 2, 3, 4]`
`[4, 1, 2, 3]`
`[1, 2, 3, 4, 4]`
How do you remove the element at index 2 from a list named `my_list`?
`my_list.remove(2)`
`my_list.pop(2)`
`my_list.delete(2)`
`my_list.clear(2)`
What will be the result of the following code? ```python my_list = [10, 20, 30, 40] print(my_list[1:3]) ```
`[10, 20, 30]`
`[20, 30]`
`[20, 30, 40]`
`[30, 40]`
Which of the following statements will create a list of numbers from 0 to 9?
`list(range(0, 10))`
`list(range(1, 10))`
`list(range(0, 9))`
`list(range(1, 9))`
What is the output of the following code? ```python my_list = [1, 2, 3, 4, 5] print(len(my_list)) ```
`4`
`5`
`6`
`None`
How can you concatenate two lists `list1` and `list2` in Python?
`list1 + list2`
`list1.append(list2)`
`list1.extend(list2)`
`list1 * list2`
Which of the following methods can be used to sort a list in ascending order?
`list.sort()`
`list.order()`
`list.arrange()`
`list.organize()`
What will be the output of the following code? ```python my_list = [1, 2, 3, 4, 5] my_list.reverse() print(my_list) ```
`[5, 4, 3, 2, 1]`
`[1, 2, 3, 4, 5]`
`[1, 3, 5, 2, 4]`
`[5, 3, 1, 4, 2]`
How do you check if an element exists in a list?
`element in list`
`list.contains(element)`
`list.has(element)`
`element.exists(list)`
What will be the output of the following code? ```python my_list = [1, 2, 3] my_list.insert(1, 4) print(my_list) ```
`[1, 4, 2, 3]`
`[1, 2, 3, 4]`
`[4, 1, 2, 3]`
`[1, 2, 4, 3]`
Which of the following will create a list of squares of numbers from 0 to 4?
`[x^2 for x in range(5)]`
`[x**2 for x in range(5)]`
`[x*2 for x in range(5)]`
`[x**2 for x in range(1, 5)]`
What is the result of the following code? ```python my_list = [1, 2, 3, 4, 5] print(my_list[-2]) ```
`4`
`5`
`3`
`2`
