Completed
Lists — basics
Questions From This Challenge
Q1mcq1 mark
Which of the following correctly creates a list in Python?
my_list = [1, 2, 3] ✓
my_list = (1, 2, 3)
my_list = {1, 2, 3}
my_list = <1, 2, 3>
Q2mcq1 mark
What is the index of the first element in a Python list?
0 ✓
1
-1
It depends on the list
Q3mcq1 mark
For the list nums = [10, 20, 30, 40], what does nums[-1] refer to?
The last element, 40 ✓
The first element, 10
An error since indices cannot be negative
The element at position -1 which does not exist
Q4mcq1 mark
Which statement correctly traverses and prints every element of the list my_list using a for loop?
for item in my_list: print(item) ✓
for item in my_list(): print(item)
for item to my_list: print(item)
traverse(my_list): print(item)
Q5mcq1 mark
Lists in Python are ________ data types, meaning their contents can be changed after creation.
mutable ✓
immutable
constant
static
Q6mcq1 mark
Which function returns the number of elements present in a list?
len() ✓
size()
count()
length()
Q7output1 mark
What is the output of the following code?
nums = [10, 20, 30, 40, 50] print(nums[2])
Correct output:
30Q8output1 mark
What is the output of the following code?
nums = [5, 15, 25, 35] print(nums[-2])
Correct output:
25Q9output1 mark
What is the output of the following code?
nums = list(range(1, 6)) print(nums)
Correct output:
[1, 2, 3, 4, 5]Q10output1 mark
What is the output of the following code?
nums = [1, 2, 3, 4]
for n in nums:
print(n * n)
Correct output:
1
4
9
16Q11output1 mark
What is the output of the following code?
nums = [3, 6, 9]
total = 0
for n in nums:
total = total + n
print(total)
Correct output:
18Q12output1 mark
What is the output of the following code?
data = ["Rahul", 15, 92.5] print(data)
Correct output:
['Rahul', 15, 92.5]Q13output1 mark
What is the output of the following code?
fruits = ["apple", "banana", "cherry", "mango"] print(fruits[1])
Correct output:
bananaQ14output1 mark
What is the output of the following code?
nums = [10, 20, 30] print(len(nums))
Correct output:
3Q15output1 mark
What is the output of the following code?
nums = [1, 2, 3] nums[1] = 99 print(nums)
Correct output:
[1, 99, 3]