- Predict the output
L = [4,5,6,4,2,8,10,34]
L[::3]=[100,200,300]
print(L)
a. [4, 4, 10]
b. [100,200,300]
c. [100, 5, 6, 200, 2, 8, 300, 34]
d. [4,100,100,4,200,200,10,300]
Show Answer
c. [100, 5, 6, 200, 2, 8, 300, 34]
- Predict the output
L = [4,5,6,4,2,8,10,34]
L[:4]=range(10,50,10)
print(L)
a. [10,5,6,4,20,8,10,30]
b. [4,5,6,4,10,20,30,40]
c. [10, 20, 30, 40, 2, 8, 10, 34]
d. Produce Error
Show Answer
c. [10, 20, 30, 40, 2, 8, 10, 34]
- Predict the output
L = [4,5,6,4,2,8,10,34]
L[3:6]=[11,22,33]
print(L)
a. [4,5,11,22,33,8,10,34]
b. [4,5,6,11,22,33,10,34]
c. [4,5,11,22,33,0,10,34]
d. Produce Error
Show Answer
b. [4,5,6,11,22,33,10,34]
- What will be the output of the following code segment?
List1 = [1,2,3,4,5,6,7,8,9,10]
for i in range(0,len(myList)):
if i%2 == 0:
print(List1[i], end = “ “)
a. 1 3 5 7 9
b. 2 4 6 8 10
c. 0 2 4 6 8
d. Error
Show Answer
a. 1 3 5 7 9
- What will be the output of the following code segment?
List1 = [1,2,3,4,5,6,7,8,9,10]
del List1[:4]
print(List1)
a. [1 2 3 4]
b. [ 5 6 7 8 9 10]
c. [6 7 8 9 10]
d. Error
Show Answer
b. [ 5 6 7 8 9 10]
- What will be the output of the following code segment?
List1 = [1,2,3,4,5,6,7,8,9,10]
del List1[::3]
print(List1)
a. [2,3,5,6,8,9]
b. [1,4,7,10]
c. [5,6,7,8,9,10]
d. [3,6,9]
Show Answer
a. [2,3,5,6,8,9]
- What will be the output of the following code segment?
List1 = [2,4]
List1 *= 3
print(List1)
a. [6,12]
b. [8,64]
c. [2,4,2,4,2,4]
d. [[2,4],[2,4],[2,4]
Show Answer
c. [2,4,2,4,2,4]
- Which of the following data type falls under mapping?
a. List
b. Tuple
c. String
d. Dictionary
Show Answer
d. Dictionary
- Which of the following is NOT true about dictionary?
a. Items stored in dictionary are unordered.
b. Duplicate keys are allowed in dictionary.
c. Items in dictionary are stored as key:value pair.
d. Keys of dictionary are immutable and values are mutable.
Show Answer
b. Duplicate keys are allowed in dictionary.
- Select the correct statement.
i. A dictionary can have duplicate values for different keys
ii. The values of dictionary can be accessed using indexes
a. i true, ii false
b. i false, ii true
c. both true
d. both false
Show Answer
a. i true, ii false
- Which of the following is correct syntax for defining a dictionary?
a. D = {[‘a’,10],[‘b’,20]}
b. D = {(‘a’,10),(‘b’,20)}
c. D = {‘a’,10:’b’,20}
d. D = {‘a’:10,’b’:20}
Show Answer
d. D = {‘a’:10,’b’:20}
- The length of dictionary is equal to
a. Length of values of dictionaries
b. Length of keys of dictionaries
c. Length of key:value pairs of dictionary
d. Length of index of dictionary
Show Answer
c. Length of key:value pairs of dictionary
- Method used to return all keys of dictionary is
a. key()
b. keys()
c. value()
d. values()
Show Answer
b. keys()
- method which returns all the items (key:value) of dictionary as tuple is
a. dict()
b. items()
c. get()
d. keys()
Show Answer
b. items()
- When we add a new key:value pair to dictionary, it increases the size of dictionary beyond its original size, an d hence an error occurs.
a. True
b. False
Show Answer
b. False
- We can not use list as key for a dictionary because
i. List are mutable and keys are immutable
ii. List are collection of items and keys are represented with single item
a. both true
b. both false
c. i true, ii false
d. i false, ii true
Show Answer
a. both true
- Slicing cannot be applied on dictionaries because
a. Dictionary stores items as key: value pair
b. Dictionary is not sequence, items stored in it are unordered
c. Dictionary keys are immutable
d. Dictionary keys cannot taken as list
Show Answer
b. Dictionary is not sequence, items stored in it are unordered
- If we want to store our friends mobile no with their name, which data type would be more suitable for us?
a. List
b. String
c. Tuple
d. Dictionary
Show Answer
d. Dictionary
- If we wish to store book details including its name and price, which of the following would be best suitable option?
a. List
b. String
c. Tuple
d. Dictionary
Show Answer
d. Dictionary
- Select the correct statement to merge and store a dictionary D2 in D1.
a. D1.extend(D2)
b. D1.get(D2)
c. D1.update(D2)
d. D1.append(D2)
Show Answer
c. D1.update(D2)
- Predict the output of given code:
d1 = {‘a’:10,’b’:20}
d2 = {‘c’:30,’d’:40}
d1.update(d2)
print(d1)
a. {‘a’:10,’b’:20, {‘c’:30,’d’:40}}
b. {{‘a’:10,’b’:20}, {‘c’:30,’d’:40}}
c. {‘a’:10,’b’:20, ‘c’:30,’d’:40}
d. {‘a’:10,’b’:20, [‘c’:30,’d’:40]}
Show Answer
c. {‘a’:10,’b’:20, ‘c’:30,’d’:40}
- In the previous question, what code one can write to add 50 with key ‘e’ in dictionary d1.
a. d1.add(‘e’:50)
b. d1[‘e’]=50
c. d1.e = 50
d. d1.keys(‘e’) = 50
Show Answer
b. d1[‘e’]=50
- for the given dictionary
d1 = {‘a’:10,’b’:20, ‘c’:30,’d’:40}
which of the following code will display value 30
a. d1[‘c’]
b. d1.get(‘c’)
c. d1.keys(‘c’)
d. both a and b
E. all a, b and c
Show Answer
d. both a and b
- What will be output of following code?
d = {‘c’:30,’d’:40}
print(d.items())
a. dict_items([(‘c’, 30), (‘d’, 40)])
b. dict_items ({(‘c’, 30), (‘d’, 40)})
c. dict_items ([[‘c’, 30], [‘d’, 40]])
d. dict_items ([‘c’->30, ‘d’->40])
Show Answer
a. dict_items[(‘c’, 30), (‘d’, 40)]
- What will be output of following code?
d = {‘c’:30,’d’:40}
print(d.values())
a. dict_values([30, 40])
b. dict_values((30, 40))
c. dict_values(30,40)
d. dict_values[30, 40]
Show Answer
a. dict_values([30, 40])