Computer Science - Informatics Practices Class XI/XII Python Dictionary Solved Test Part 5
Q1. Explain the following functions in reference to dictionary.
a. items()
b. keys()
c. values()
Q2. Write the output of the following:
- a(6) = 60
- a.len()
- a.clears()
- a.gets(3)
- a.item()
- a.valueS()
- a.keyS()
- a.del(4)
- pop(4)
SOLUTIONS
Q1. Explain the following functions in reference
to dictionary.
a. items()
b. keys()
c. values()
Ans. a. items() : This method returns the content
of dictionary as a list of tuples having key-value
pairs.
b. keys() : It returns the list of key values in
dictionary.
c. values(): It returns the list of values from
dictionary.
Q2. Write the output of the following:
List | Dictionary |
Elements are enclosed in square brackets | Elements are enclosed in curly braces |
Index value is an integer only | Index value can be of any type. |
- a(6) = 60
- a.len()
- a.clears()
- a.gets(3)
- a.item()
- a.valueS()
- a.keyS()
- a.del(4)
- pop(4)
- a[6]=60
- len(a)
- a.clear()
- a.get(3)
- a.items
- a.values()
- a.keys()
- del a[4]
- a.pop(4)