Informatics Practices
Answer
| String | Dictionary |
|---|---|
| A string is a sequence of characters enclosed in quotes. | A dictionary is a collection of key-value pairs enclosed in curly braces {}. |
| It is immutable. | It is mutable. |
| Strings are ordered collection of objects. | Dictionaries are unordered collections of objects. |
| For example, "hello", '123' etc. | For example, {1: 'a', 2 : 'b'} etc |
Related Questions
Assertion (A): Consider the code given below:
d={1: 'Amit', 2: 'Sumit', 5:'Kavita'} d.pop(1) print(d)The output will be:
Amit #item is returned after deletion {2: 'Sumit', 5: 'Kavita'}Reasoning (R): pop() method not only deletes the item from the dictionary but also returns the deleted value.
- 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 is a key-value pair in dictionary?
Find errors and rewrite the same after correcting the following code:
d1 = {1:10, 2.5:20, 3:30, 4:40, 5:50, 6:60, 7:70}Find errors and rewrite the same after correcting the following code:
d1(9) = 90