Multiple Choice Questions -list & Dictionary

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Aparnasunil75
A
Aparnasunil75
Community Contributor
Quizzes Created: 20 | Total Attempts: 43,504
| Attempts: 1,548 | Questions: 28
Please wait...
Question 1 / 28
0 %
0/100
Score 0/100
1. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.extend([34, 5])?

Explanation

The correct answer is [3, 4, 5, 20, 5, 25, 1, 3, 34, 5]. After the listExample.extend([34, 5]) operation, the elements [34, 5] are added to the end of the listExample. Therefore, the resulting list1 will be [3, 4, 5, 20, 5, 25, 1, 3, 34, 5].

Submit
Please wait...
About This Quiz
Multiple Choice Questions -list & Dictionary - Quiz

This quiz assesses knowledge on Python lists and dictionaries, covering creation, manipulation, and built-in functions. It is designed for learners to test their understanding of basic data structures... see morein Python, crucial for programming and software development. see less

2. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.reverse()?

Explanation

The reverse() method in Python reverses the order of elements in a list. So, after applying list1.reverse(), the list1 will be reversed and the elements will be in the order [3, 1, 25, 5, 20, 5, 4, 3].

Submit
3. Suppose list1 is [2445,133,12454,123], what is max(list1)?

Explanation

The correct answer is 12454 because it is the highest number in the given list, which consists of four numbers.

Submit
4. Suppose list1 is [1, 5, 9], what is sum(list1)?

Explanation

The correct answer is 15 because the sum of the numbers in list1 [1, 5, 9] is 1 + 5 + 9 = 15.

Submit
5. To add a new element to a list we use which command?

Explanation

The correct answer is list1.append(5). This is because the append() function is specifically designed to add elements to the end of a list. The add() function is not a valid command for adding elements to a list. Similarly, addLast() and addEnd() are not standard commands in Python for adding elements to a list. Therefore, list1.append(5) is the correct command to use in this case.

Submit
6. Suppose listExample is ['h','e','l','l','o'], what is len(listExample)?

Explanation

The len() function in Python returns the length of a list, which is the number of elements in the list. In this case, the listExample contains 5 elements: 'h', 'e', 'l', 'l', and 'o'. Therefore, the length of listExample is 5.

Submit
7. What will be the output of the following Python code? list1 = [1, 2, 3, 4] list2 = [5, 6, 7, 8] print(len(list1 + list2))

Explanation

The code first concatenates list1 and list2 using the + operator, resulting in a new list [1, 2, 3, 4, 5, 6, 7, 8]. The len() function is then used to determine the length of this new list, which is 8. Therefore, the output of the code will be 8.

Submit
8. Which of the following statements create a dictionary?

Explanation

All three statements create a dictionary. In the first statement, an empty dictionary is created with no key-value pairs. In the second statement, a dictionary is created with two key-value pairs, "john" with a value of 40 and "peter" with a value of 45. In the third statement, a dictionary is created with two key-value pairs, 40 with a value of "john" and 45 with a value of "peter". Therefore, all of the mentioned statements create a dictionary.

Submit
9. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?

Explanation

The correct answer is 25 because list1[-1] refers to the last element in the list, and in this case, the last element is 25.

Submit
10. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?

Explanation

not-available-via-ai

Submit
11. What will be the output of the following Python code snippet? d = {"john":40, "peter":45} "john" in d

Explanation

The output of the given code snippet will be "true". This is because the code checks if the key "john" exists in the dictionary "d". Since "john" is one of the keys in the dictionary, the condition is satisfied and the output is "true".

Submit
12. To which of the following the "in" operator can be used to check if an item is in it?

Explanation

The "in" operator can be used to check if an item is in lists, dictionaries, and sets. In lists, it checks if the item is present in the list. In dictionaries, it checks if the item is a key in the dictionary. In sets, it checks if the item is an element in the set. Therefore, the correct answer is that the "in" operator can be used to check if an item is in all of the mentioned data structures.

Submit
13. Suppose list1 is [1, 3, 2], What is list1 * 2?

Explanation

The correct answer is [1, 3, 2, 1, 3, 2] because when you multiply a list by a number, it repeats the elements of the list that number of times. In this case, multiplying list1 by 2 repeats the elements of list1 twice, resulting in [1, 3, 2, 1, 3, 2].

Submit
14. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?

Explanation

After executing the code listExample.pop(1), the element at index 1 (which is 4) is removed from the list. The resulting list will be [3, 5, 20, 5, 25, 1, 3].

Submit
15. Which of the following commands will create a list?  

Explanation

All of the mentioned commands will create a list. The first command "list1 = list()" creates an empty list using the list() constructor. The second command "list1 = []" creates an empty list using square brackets. The third command "list1 = list([1, 2, 3])" creates a list with elements 1, 2, and 3 using the list() constructor. Therefore, all of these commands will create a list.

Submit
16. What is the output when we execute list("hello")?

Explanation

Executing the command list("hello") will convert the string "hello" into a list of individual characters: ['h', 'e', 'l', 'l', 'o'].

Submit
17. What will be the output of the following Python code? >>>list("a#b#c#d".split('#'))

Explanation

The code is using the split() method to split the string "a#b#c#d" at each occurrence of the "#" character. This will result in a list of substrings ['a', 'b', 'c', 'd']. Therefore, the correct answer is [‘a’, ‘b’, ‘c’, ‘d’].

Submit
18. What will be the output of the following Python code snippet? >>> a={1:"A",2:"B",3:"C"} >>> del a

Explanation

The code snippet is creating a dictionary named 'a' with three key-value pairs. The 'del' keyword is then used to delete the dictionary 'a'. Therefore, the output of the code will be that the entire dictionary 'a' will be deleted.

Submit
19. What will be the output of the following Python code? >>>"Welcome to Python".split()

Explanation

The given Python code uses the split() function on the string "Welcome to Python". The split() function splits the string into a list of substrings based on the specified delimiter, which is a space in this case. Therefore, the output of the code will be a list containing the substrings "Welcome", "to", and "Python".

Submit
20. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

Explanation

list1[:-1] is a slicing operation on list1. In Python, slicing allows us to extract a portion of a list. The syntax for slicing is list[start:end], where start is the index of the first element to include and end is the index of the first element to exclude. In this case, list1[:-1] means to slice the list from the beginning to the second last element, excluding the last element. So, the correct answer is [2, 33, 222, 14].

Submit
21. What will be the output of the following Python code snippet? d = {"john":40, "peter":45}

Explanation

The correct answer is "john" and "peter". This is because the code snippet defines a dictionary named 'd' with two key-value pairs: "john":40 and "peter":45. When we access the keys of the dictionary using the 'd.keys()' method, it returns an iterable containing the keys "john" and "peter".

Submit
22. Which of these about a dictionary is false?

Explanation

A dictionary in Python is a data structure that stores key-value pairs. The statement "The keys of a dictionary can be accessed using values" is false because in a dictionary, the values can be accessed using keys, but not the other way around. The keys are unique and act as identifiers for the corresponding values. Therefore, it is not possible to directly access keys using values in a dictionary.

Submit
23. Which of the statements about dictionary values if false?

Explanation

A dictionary in Python allows multiple keys to have the same value. This means that more than one key can have the same value, making the statement "Values of a dictionary must be unique" false.

Submit
24. What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} for i,j in a.items():     print(i,j,end=" ")

Explanation

The code snippet defines a dictionary 'a' with key-value pairs. The for loop iterates over the items of the dictionary, where 'i' represents the key and 'j' represents the value. Inside the loop, it prints 'i' and 'j' with a space in between, using the 'end' parameter to prevent a new line after each print statement. Therefore, the output will be "1 A 2 B 3 C", as it prints the keys and values of the dictionary separated by a space.

Submit
25. Which of the following is not a declaration of the dictionary?

Explanation

The correct answer is {1,”A”,2”B”} because it is missing the colon (:) between the keys and values in the dictionary. In Python, a dictionary declaration should have the format {key: value}.

Submit
26. If a is a dictionary with some key-value pairs, what does a.popitem() do?

Explanation

The popitem() method in a dictionary removes an arbitrary key-value pair from the dictionary. It does not remove all the key-value pairs or a specific key-value pair for a given key. This method is a valid method for dictionaries.

Submit
27. What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(1,4))

Explanation

The code snippet creates a dictionary named "a" with key-value pairs 1:"A", 2:"B", and 3:"C". The "get" method is used to retrieve the value associated with the key 1 from the dictionary. Since the key 1 exists in the dictionary, the method returns the value "A". Therefore, the output of the code will be "A".

Submit
28. What will be the output of the following Python code snippet? a={1:"A",2:"B",3:"C"} print(a.get(5,4))

Explanation

The code snippet creates a dictionary 'a' with keys 1, 2, and 3 mapped to values "A", "B", and "C" respectively. The print statement uses the get() method to retrieve the value corresponding to key 5 from the dictionary. Since the key 5 does not exist in the dictionary, the get() method returns the default value provided as the second argument, which is 4. Therefore, the output of the code will be 4.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 22, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 16, 2020
    Quiz Created by
    Aparnasunil75
Cancel
  • All
    All (28)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after...
Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after...
Suppose list1 is [2445,133,12454,123], what is max(list1)?
Suppose list1 is [1, 5, 9], what is sum(list1)?
To add a new element to a list we use which command?
Suppose listExample is ['h','e','l','l','o'], what is...
What will be the output of the following Python code? ...
Which of the following statements create a dictionary?
Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after...
What will be the output of the following Python code snippet? ...
To which of the following the "in" operator can be used to check if an...
Suppose list1 is [1, 3, 2], What is list1 * 2?
Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after...
Which of the following commands will create a list?  
What is the output when we execute list("hello")?
What will be the output of the following Python code? ...
What will be the output of the following Python code snippet? ...
What will be the output of the following Python code? ...
Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
What will be the output of the following Python code snippet? ...
Which of these about a dictionary is false?
Which of the statements about dictionary values if false?
What will be the output of the following Python code snippet? ...
Which of the following is not a declaration of the dictionary?
If a is a dictionary with some key-value pairs, what does a.popitem()...
What will be the output of the following Python code snippet? ...
What will be the output of the following Python code snippet? ...
Alert!

Advertisement