# Multiple Choice Questions-tuples & Dictionaries

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Aparnasunil75
A
Aparnasunil75
Community Contributor
Quizzes Created: 20 | Total Attempts: 37,331
Questions: 20 | Attempts: 1,921

Settings

.

• 1.

### To which of the following the “in” operator can be used to check if an item is in it?

• A.

Lists

• B.

Dictionary

• C.

Tuples

• D.

All of the above

D. All of the above
Explanation
The "in" operator can be used to check if an item is in Lists, Dictionary, and Tuples. This operator checks if the item is present in the given data structure and returns a boolean value (True or False) accordingly. Therefore, the correct answer is "All of the above" as the "in" operator can be used with all three data structures.

Rate this question:

• 2.

### Which of the following is a Python tuple?

• A.

[1, 2, 3]

• B.

(1,2,3)

• C.

{1, 2, 3}

• D.

{}

B. (1,2,3)
Explanation
A Python tuple is a collection of ordered and immutable elements. In the given options, only (1,2,3) is a tuple because it is enclosed in parentheses and contains comma-separated values. The other options ([1, 2, 3], {1, 2, 3}, {}) are lists, sets, and dictionaries respectively, as they are enclosed in square brackets, curly braces, and curly braces with key-value pairs.

Rate this question:

• 3.

### Suppose t = (1, 2, 4, 3), which of the following is incorrect?

• A.

Print(t[3])

• B.

T[3] = 45

• C.

Print(max(t))

• D.

Print(len(t))

B. T[3] = 45
Explanation
The given answer is incorrect because it tries to assign a new value (45) to the element at index 3 of the tuple t. However, tuples are immutable in Python, which means their elements cannot be modified once they are assigned. Therefore, trying to assign a new value to t[3] will result in a TypeError.

Rate this question:

• 4.

### What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:3]

• A.

(1, 2)

• B.

(1, 2, 4)

• C.

(2,4)

• D.

(2, 4, 3)

C. (2,4)
Explanation
The code is using slicing on the tuple t. The syntax t[1:3] means to select elements from index 1 up to, but not including, index 3. In the tuple t, the element at index 1 is 2 and the element at index 2 is 4. Therefore, the output will be (2, 4).

Rate this question:

• 5.

### What will be the output of the following Python code? >>>t=(1,2,4,3) >>>t[1:-1]

• A.

(1, 2)

• B.

(1, 2, 4)

• C.

(2,4)

• D.

(2, 4, 3)

C. (2,4)
Explanation
The code is using slicing to extract a portion of the tuple 't'. The syntax t[1:-1] means to start from the element at index 1 (which is 2) and go up to, but not including, the element at the last index (which is 3). Therefore, the output will be (2, 4).

Rate this question:

• 6.

### What will be the output of the following Python code? >>>t = (1, 2, 4, 3, 8, 9) >>>[t[i] for i in range(0, len(t), 2)]

• A.

[2, 3, 9]

• B.

[1, 2, 4, 3, 8, 9]

• C.

[1, 4, 8]

• D.

(1, 4, 8)

C. [1, 4, 8]
Explanation
range(0, len(t), 2) generates the indices of t with a step size of 2: [0, 2, 4].
The list comprehension [t[i] for i in range(0, len(t), 2)] iterates over these indices and retrieves the elements from the tuple t.
The retrieved elements are (1, 4, 8).

Rate this question:

• 7.

### What will be the output of the following Python code? d = {"john":40, "peter":45} d["john"]

• A.

40

• B.

45

• C.

“john”

• D.

“peter”

A. 40
Explanation
The given Python code creates a dictionary called "d" with two key-value pairs: "john" with a value of 40 and "peter" with a value of 45. The line "d["john"]" accesses the value associated with the key "john" in the dictionary "d". Since the value of "john" is 40, the output of the code will be 40.

Rate this question:

• 8.

### What will be the output of the following Python code? >>>t = (1, 2) >>>2 * t

• A.

(1, 2, 1, 2)

• B.

[1, 2, 1, 2]

• C.

(1, 1, 2, 2)

• D.

[1, 1, 2, 2]

A. (1, 2, 1, 2)
Explanation
The code multiplies the tuple t by 2, resulting in a new tuple with the elements of t repeated twice. Therefore, the output will be (1, 2, 1, 2).

Rate this question:

• 9.

### What will be the output of the following Python code? >>>t1 = (1, 2, 4, 3) >>>t2 = (1, 2, 3, 4) >>>t1 < t2

• A.

True

• B.

False

• C.

Error

• D.

None

B. False
Explanation
The code is comparing two tuples t1 and t2 using the less than operator. In Python, when comparing tuples, it compares the elements at corresponding indices. The comparison is done element by element until a mismatch is found. In this case, the first mismatch occurs at index 2, where t1 has the element 4 and t2 has the element 3. Since 4 is greater than 3, t1 is considered greater than t2. Therefore, the output of the code will be False.

Rate this question:

• 10.

### Which of the following statements create a dictionary?

• A.

D = {}

• B.

D = {“john”:40, “peter”:45}

• C.

D = {40:”john”, 45:”peter”}

• D.

All of the mentioned

D. All of the mentioned
Explanation
All of the mentioned statements create a dictionary. In Python, a dictionary is a collection of key-value pairs enclosed in curly braces {}. The first statement, d = {}, creates an empty dictionary. The second statement, d = {"john":40, "peter":45}, creates a dictionary with two key-value pairs, where "john" is the key and 40 is the value, and "peter" is the key and 45 is the value. The third statement, d = {40:"john", 45:"peter"}, also creates a dictionary with two key-value pairs, but the keys are integers (40 and 45) and the values are strings ("john" and "peter"). Therefore, all of the mentioned statements create a dictionary.

Rate this question:

• 11.

### What will be the output of the following Python code snippet? d = {"john":40, "peter":45} print(d)

• A.

“john”, 40, 45, and “peter”

• B.

{'john': 40, 'peter': 45}

• C.

40 and 45

• D.

D = (40:”john”, 45:”peter”)

B. {'john': 40, 'peter': 45}
Explanation
This output shows the key-value pairs of the dictionary, where "john" maps to 40 and "peter" maps to 45.

Rate this question:

• 12.

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

• A.

True

• B.

False

• C.

None

• D.

Error

A. True
Explanation
The code snippet creates a dictionary "d" with two key-value pairs. The key "john" has a value of 40 and the key "peter" has a value of 45. The line "john in d" checks if the key "john" is present in the dictionary "d". Since it is present, the output will be True.

Rate this question:

• 13.

### Which of these about a dictionary is false?

• A.

The values of a dictionary can be accessed using keys

• B.

The keys of a dictionary can be accessed using values

• C.

Dictionaries aren’t ordered

• D.

Dictionaries are mutable

B. The keys of a dictionary can be accessed using values
Explanation
This statement is false because in a dictionary, the keys are used to access the corresponding values, not the other way around. Keys in a dictionary are unique and serve as identifiers for the values they are associated with. Therefore, it is not possible to access the keys using the values in a dictionary.

Rate this question:

• 14.

### Which of the following is not a declaration of the dictionary?

• A.

{1: ‘A’, 2: ‘B’}

• B.

Dict([[1,”A”],[2,”B”]])

• C.

{1,”A”,2”B”}

• D.

{ }

C. {1,”A”,2”B”}
Explanation
The correct answer is {1,”A”,2”B”} because it is missing the colon (:) between the keys and values, which is necessary for declaring a dictionary in Python. The other options are valid declarations of dictionaries.

Rate this question:

• 15.

### 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=" ")

• A.

1 A 2 B 3 C

• B.

1 2 3

• C.

A B C

• D.

1:”A” 2:”B” 3:”C”

A. 1 A 2 B 3 C
Explanation
The code snippet creates a dictionary named 'a' with keys 1, 2, and 3, and corresponding values "A", "B", and "C" respectively. The for loop iterates through the items in the dictionary, which pairs each key with its corresponding value. The print statement prints each key-value pair, separated by a space, using the 'end' parameter to prevent a new line after each pair. Therefore, the output will be "1 A 2 B 3 C".

Rate this question:

• 16.

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

• A.

1

• B.

A

• C.

4

• D.

Invalid syntax for get method

B. A
Explanation
The given Python code snippet creates a dictionary called "a" with keys 1, 2, and 3 and corresponding values "A", "B", and "C" respectively. The code then uses the get() method to retrieve the value associated with key 1 from the dictionary "a". Since the key 1 exists in the dictionary, the get() method returns the value "A". Therefore, the output of the code will be "A".

Rate this question:

• 17.

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

• A.

Error, invalid syntax

• B.

A

• C.

5

• D.

4

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

Rate this question:

• 18.

### Which of the statements about dictionary values if false?

• A.

More than one key can have the same value

• B.

The values of the dictionary can be accessed as dict[key]

• C.

Values of a dictionary must be unique

• D.

Values of a dictionary can be a mixture of letters and numbers

C. Values of a dictionary must be unique
Explanation
The statement "Values of a dictionary must be unique" is false because in a dictionary, multiple keys can have the same value. This means that different keys can be associated with the same value in a dictionary.

Rate this question:

• 19.

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

• A.

Method del doesn’t exist for the dictionary

• B.

Del deletes the values in the dictionary

• C.

Del deletes the entire dictionary

• D.

Del deletes the keys in the dictionary

C. Del deletes the entire dictionary
Explanation
When you use del with a variable holding a dictionary, it deletes the entire dictionary, not just the keys or values. So in this case, executing del a would remove the entire dictionary a from memory.

Rate this question:

• 20.

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

• A.

Removes an arbitrary element

• B.

Removes all the key-value pairs

• C.

Removes the key-value pair for the key given as an argument

• D.

Invalid method for dictionary

A. Removes an arbitrary element
Explanation
The method a.popitem() removes an arbitrary element from the dictionary a. This means that it will remove and return any key-value pair from the dictionary, without any specific order or pattern. It is a valid method for dictionaries and can be used to remove elements when the specific key is not known or does not matter.

Rate this question:

Quiz Review Timeline +

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

• Current Version
• Mar 01, 2024
Quiz Edited by
ProProfs Editorial Team
• Mar 18, 2020
Quiz Created by
Aparnasunil75

Related Topics