13. Python Lists - Quiz

1. Which of the following commands will correctly create a list in Python?
Answer: All of the mentioned
2. Suppose list1 is [2, 33, 222, 14, 25]. What is the result of list1[-1]?
Answer: 25
3. Which method is used to add a single element to the end of a list?
Answer: append()
4. What is the output when executing list("hello")?
Answer: ['h', 'e', 'l', 'l', 'o']
5. Which function returns the number of elements in a list?
Answer: len()
6. What is the output of the following code?

list1 = [1, 2, 3]
list2 = list1
list1[0] = 4
print(list2)
Answer: [4, 2, 3]
7. What is the primary difference between list.sort() and the sorted() function?
Answer: sort() modifies the list in place and returns None, while sorted() returns a new sorted list.
8. What will be the output of the following code?

numbers = [4, 2, 8, 1]
result = numbers.sort()
print(result)

Answer: None
9. Which parameter is used to sort a list in descending order?
Answer: reverse=True
10. Consider the following code snippet. What is the output?

words = ["apple", "banana", "kiwi", "cherry"]
words.sort(key=len)
print(words)

Answer: ['kiwi', 'apple', 'banana', 'cherry']
11. What is the output of the following code?

my_list = [10, 20, 30]
print(my_list.reverse())

Answer: None
12. Which of the following methods returns a new reversed list without modifying the original?
Answer: list[::-1]
Score: 0 / 0 answered