Computer Science
Assertion (A): You can add an element in a dictionary using key:value pair.
Reasoning (R): A new (key:value) pair is added only when the same key doesn't exist in the dictionary. If the key is already present, then the existing key gets updated and the new entry will be made in the dictionary.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Python Dictionaries
1 Like
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
In Python, dictionaries are mutable, which means we can modify the key:value pairs, add new pairs, or remove existing pairs after the dictionary is created. When adding a new key:value pair to a dictionary, if the key already exists, its corresponding value will be updated. Otherwise, a new (key:value) pair will be added to the dictionary.
Answered By
3 Likes
Related Questions
Assertion (A): There is no difference between a list and a tuple in Python.
Reasoning (R): The list elements are enclosed within square brackets [] separated by commas and the tuple elements are enclosed within parentheses () separated by commas.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): Both max() and min() functions are implemented on lists as well as tuples in Python.
Reasoning (R): The max() and min() functions return the highest and the lowest among a set of values stored in a list or tuple respectively.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
What are the advantages of Python programming language?
In how many different ways, can you work in Python?