Tuples in Python are:
Tuples and Dictionaries — Important Questions
SUMMARY: This chapter introduces tuples and dictionaries in Python, focusing on their properties, usage, and differences from other data structures.
KEY TOPICS: tuples, dictionaries, immutable data types, key-value pairs, accessing elements, iterating over tuples and dictionaries, dictionary methods, tuple operations, nested data structures, applications of tuples and dictionaries
A tuple is created using:
Check answerHide answer
Which method returns all the keys of a dictionary?
Check answerHide answer
Dictionaries in Python store data as:
Check answerHide answer
The output of {1:'a' 2:'b'}[2] is:
Check answerHide answer
What is the primary characteristic of a tuple in Python?
Check answerHide answer
Which of the following methods can be used to remove a key-value pair from a dictionary?
Check answerHide answer
How can you access the first element of a tuple named 'my_tuple'?
Check answerHide answer
Which of the following is true about dictionaries in Python?
Check answerHide answer
What will be the output of the expression len((1, 2, 3, 4))?
Check answerHide answer
Which of the following statements correctly creates a dictionary?
Check answerHide answer
What is the result of the expression (1, 2) + (3, 4)?
Check answerHide answer
Which method would you use to get a list of all values in a dictionary?
Check answerHide answer
What happens if you try to change an element of a tuple?
Check answerHide answer
In a dictionary, what is the purpose of a key?
Check answerHide answer
Differentiate between list and tuple in Python.
Differentiate between tuple and dictionary in Python.
Write Python code to count the frequency of each word in a sentence using a dictionary.
Explain how to create an empty tuple and an empty dictionary.
How do you check if a key exists in a dictionary?
What are the main characteristics of tuples in Python?
View sample solutionHide solution
How can you access elements in a tuple?
View sample solutionHide solution
What is the purpose of the 'get' method in dictionaries?
View sample solutionHide solution
Explain how to iterate over a dictionary and print its key-value pairs.
View sample solutionHide solution
What happens if you try to change an element of a tuple?
View sample solutionHide solution
Compare tuple and dictionary with the help of a table on five features.
Differentiate between list tuple and dictionary in tabular form on five points.
Compare keys() and values() dictionary methods with the help of a table.
Write a Python program to convert two parallel lists into a dictionary.
Discuss any five built-in dictionary methods with one example each.
Write a Python program using a dictionary to store student names as keys and their marks as values then find the topper.
Assertion (A): Tuples are immutable.
Reason (R): They cannot be modified after creation.
Show explanationHide explanation
Assertion (A): Dictionaries are unordered collections.
Reason (R): Items are accessed by key not position.
Show explanationHide explanation
Assertion (A): Dictionary keys must be unique.
Reason (R): Duplicate keys would create ambiguity.
Show explanationHide explanation
Assertion (A): Dictionary keys must be immutable.
Reason (R): Lists cannot be used as dictionary keys.
Show explanationHide explanation
Assertion (A): Tuples can be used as dictionary keys.
Reason (R): They are immutable and hashable.
Show explanationHide explanation
Assertion (A): Tuples can contain elements of different data types.
Reason (R): Dictionaries can only store values of the same data type.
Show explanationHide explanation
Assertion (A): You can access elements of a tuple using indexing.
Reason (R): Dictionaries use indexing to access their values.
Show explanationHide explanation
Assertion (A): Dictionaries allow duplicate keys.
Reason (R): Dictionaries store data in key-value pairs.
Show explanationHide explanation
Statement 1: Tuples are faster than lists for iteration.
Statement 2: They have lower memory overhead.
Show answerHide answer
Statement 1: Dictionary values can be of any data type.
Statement 2: Keys must be of immutable types like int float string or tuple.
Show answerHide answer
Statement 1: Tuples are written using parentheses.
Statement 2: A single-element tuple needs a trailing comma.
Show answerHide answer
Statement 1: The get() method retrieves a value for a given key.
Statement 2: It returns None if the key is absent.
Show answerHide answer
Statement 1: The items() method returns key-value pairs as a list of tuples.
Statement 2: It is useful for iterating over dictionary entries.
Show answerHide answer
Statement 1: Tuples can be modified after their creation.
Statement 2: Dictionaries are mutable data types.
Show answerHide answer
Statement 1: A tuple can contain elements of different data types.
Statement 2: Dictionaries can only have string keys.
Show answerHide answer
Statement 1: The length of a tuple can be changed after it is created.
Statement 2: Dictionaries allow for duplicate keys.
Show answerHide answer
-
Which Python data type stores key-value pairs?AListBTupleCDictionaryDSet
-
Tuples in Python are:AMutableBImmutableCHashableDBoth immutable and hashable
-
Write a Python program to implement a phone book with add search update and delete operations.
Show answersHide answers
-
What is the main characteristic of tuples in Python?AThey are mutable.BThey are immutable.CThey can only hold integers.DThey can only hold strings.
-
Explain why dictionaries are preferred for fast data retrieval.
-
Which of the following is true about the keys in a dictionary?AKeys can be duplicated.BKeys must be unique.CKeys can be mutable.DKeys can only be strings.
-
Provide an example of a scenario where a tuple would be more appropriate than a list.
Show answersHide answers
-
What type of data structure is best suited for storing a fixed collection of items?AListBTupleCDictionaryDSet
-
Describe a situation where using a dictionary would be advantageous.
-
Which of the following statements about tuples is correct?ATuples can be modified after creation.BTuples can contain mixed data types.CTuples cannot be nested.DTuples are slower than lists.
-
What is a common application of dictionaries in programming?
Show answersHide answers
-
How are tuples created in Python?AUsing square brackets.BUsing parentheses.CUsing curly braces.DUsing angle brackets.
-
Explain why tuples can be used as keys in dictionaries.
-
Which of the following is the correct syntax for a dictionary?A{'key': 'value'}B[key: value]C(key, value)D<key, value>
-
Provide an example of a tuple that could be used as a key in a dictionary.
Show answersHide answers
For dict d = {'a':1, 'b':2, 'c':3}, predict each operation's result.
| Operation on d = {'a':1,'b':2,'c':3} | Result |
|---|---|
| d['a'] | ? |
| d['d'] = 4 (then d) | ? |
| d.keys() | ? |
| d.values() | ? |
| d.get('e', 0) | ? |
Predict the output of each tuple operation.
| Operation on t = (1, 2, 3, 4) | Result |
|---|---|
| len(t) | ? |
| t[0] | ? |
| t[-1] | ? |
| t[0:2] | ? |
| t + (5, 6) | ? |
| t * 2 | ? |
Study the table comparing list tuple and dictionary and answer:
| Feature | List | Tuple | Dictionary |
|---|---|---|---|
| Mutable? | Yes | No | Yes |
| Ordered? | Yes | Yes | Yes (3.7+) |
| Indexed by | Position | Position | Key |
| Syntax | [] | () | {} |
| Duplicates | Allowed | Allowed | Keys unique |
-
Which is immutable in Python?AListBTupleCDictionaryDAll three
-
Which uses curly braces { } for syntax?AListBTupleCDictionaryDSet
-
Compare list tuple and dictionary on five features with one example each.
Show answersHide answers
What is the maximum value in the tuple provided in the table?
| Tuple Elements |
|---|
| 1 |
| 5 |
| 3 |
| 7 |
| 2 |
Study the dictionary key-value lookup and answer:
-
To safely retrieve a value from a dictionary use:Ad['marks']Bd.get('marks')CBoth workDNeither works
-
Which method returns key-value pairs as tuples?Akeys()Bvalues()Citems()Dall()
-
Discuss the structure of a dictionary in Python with examples of common methods.
Show answersHide answers
Based on the given diagram of a tuple structure in Python, answer the following:
-
What is the type of the first element in the tuple?AIntegerBStringCFloatDList
-
Explain why tuples are considered immutable.
Show answersHide answers
Based on the given flowchart, answer the following:
-
Which method is used to retrieve a value associated with a key?Aadd()Bremove()Cget()Dupdate()
-
What is the purpose of the 'remove()' method?
Show answersHide answers
Based on the given chart, answer the following:
-
Which operation has a time complexity of O(1)?AAccessBCountCAppendDIndex
-
What can be inferred about the 'Append' operation for tuples?
Show answersHide answers
Make a full Computer Science paper on Tuples and Dictionaries.
Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.
Generate your paper — free