QUIZ ON : PROGRAMMING AND PROBLEM SOLVING THROUGH PYTHON - SEQUENCE DATA TYPES IN PYTHON

SEQUENCE DATA TYPES IN PYTHON

00:00:00

Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?

Option A. [3, 4, 5, 20, 5, 25, 1]
Option B. [1, 3, 3, 4, 5, 5, 20, 25]
Option C. [3, 5, 20, 5, 25, 1, 3]
Option D. [1, 3, 4, 5, 20, 5, 25]
True Answer A

Explanation :
pop() by default will remove the last element.

Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop()?

Question No# : 01 out of 20



What will be the output of the following Python code?

  1. >>>t=(1,2,4,3)
  2. >>>t[1:-1]

Option A. (1, 2)
Option B. (1, 2, 4)
Option C. (2, 4)
Option D. (2, 4, 3)
True Answer C

Explanation :
Slicing in tuples takes place just as it does in strings.

What will be the output of the following Python code?

  1. >>>t=(1,2,4,3)
  2. >>>t[1:-1]

Question No# : 02 out of 20



What will be the output of the following Python code?

>>> a={1,2,3}

>>> a.intersection_update({2,3,4,5}) 

>>> a

Option A. {2,3}
Option B. Error, duplicate item present in list
Option C. Error, no method called intersection_update for set data type
Option D. {1,4,5}
True Answer A

Explanation :
The method intersection_update returns a set which is an intersection of both the sets.

What will be the output of the following Python code?

>>> a={1,2,3}

>>> a.intersection_update({2,3,4,5}) 

>>> a

Question No# : 03 out of 20



What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}

for i,j in a.items()

print(i,j,end=" ")

Option A. 1 A 2 B 3 C
Option B. 1 2 3
Option C. A B C
Option D. 1:”A” 2:”B” 3:”C”
True Answer A

Explanation :
In the above code, variables i and j iterate over the keys and values of the dictionary respectively.

What will be the output of the following Python code snippet?

a={1:"A",2:"B",3:"C"}

for i,j in a.items()

print(i,j,end=" ")

Question No# : 04 out of 20



What will be the output of the following Python expression?

round(4.576)

Option A. 4.5
Option B. 5
Option C. 4
Option D. 4.6
True Answer B

Explanation :
This is a built-in function which rounds a number to give precision in decimal digits. In the above case, since the number of decimal places has not been specified, the decimal number is rounded off to a whole number. Hence the output will be 5.

What will be the output of the following Python expression?

round(4.576)

Question No# : 05 out of 20



Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

Option A. [0, 1, 2, 3]
Option B. [0, 1, 2, 3, 4]
Option C. [0.0, 0.5, 1.0, 1.5]
Option D. [0.0, 0.5, 1.0, 1.5, 2.0]
True Answer C

Explanation :
Execute in the shell to verify.

Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

Question No# : 06 out of 20



What will be the output of the following Python code?

  1.   values = [[3, 4, 5, 1], [33, 6, 1, 2]]
  2.    
  3.   v = values[0][0]
  4. for row in range(0, len(values)):
  5.       for column in range(0, len(values[row])):
  6.           if v < values[row][column]:
  7.               v = values[row][column]
  8.    
  9.   print(v)

Option A. 3
Option B. 5
Option C. 6
Option D. 33
True Answer D

Explanation :
Execute in the shell to verify.

What will be the output of the following Python code?

  1.   values = [[3, 4, 5, 1], [33, 6, 1, 2]]
  2.    
  3.   v = values[0][0]
  4. for row in range(0, len(values)):
  5.       for column in range(0, len(values[row])):
  6.           if v < values[row][column]:
  7.               v = values[row][column]
  8.    
  9.   print(v)

Question No# : 07 out of 20



Which of the following statements is used to create an empty set?

Option A. { }
Option B. set()
Option C. [ ]
Option D. ( )
True Answer B

Explanation :
{ } creates a dictionary not a set. Only set() creates an empty set.

Which of the following statements is used to create an empty set?

Question No# : 08 out of 20



What will be the output of the following Python code?

>>> a=(2,3,4)  >>> sum(a,3)

Option A. Too many arguments for sum() method
Option B. The method sum() doesn’t exist for tuples
Option C. 12
Option D. 9
True Answer C

Explanation :
In the above case, 3 is the starting value to which the sum of the tuple is added to.

What will be the output of the following Python code?

>>> a=(2,3,4)  >>> sum(a,3)

Question No# : 09 out of 20



What will be the output of the following Python code snippet?

total={}

def insert(items):      if items in total:          total[items] += 1      else:          total[items] = 1  insert('Apple')  insert('Ball')  insert('Apple') 

print (len(total))

Option A. 3
Option B. 1
Option C. 2
Option D. 0
True Answer C

Explanation :
The insert() function counts the number of occurrences of the item being inserted into the dictionary. There are only 2 keys present since the key ‘Apple’ is repeated. Thus, the length of the dictionary is 2.

What will be the output of the following Python code snippet?

total={}

def insert(items):      if items in total:          total[items] += 1      else:          total[items] = 1  insert('Apple')  insert('Ball')  insert('Apple') 

print (len(total))

Question No# : 10 out of 20



If a=(1,2,3,4), a[1:-1] is _________

Option A. Error, tuple slicing doesn’t exist
Option B. [2,3]
Option C. (2,3,4)
Option D. (2,3)
True Answer D

Explanation :
Tuple slicing exists and a[1:-1] returns (2,3).

If a=(1,2,3,4), a[1:-1] is _________

Question No# : 11 out of 20



What will be the output of the following Python code?

>>> import collections

>>> a=collections.OrderedDict((str(x),x) for x in range(3)) 

>>> a

Option A. {‘2’:2, ‘0’:0, ‘1’:1}
Option B. OrderedDict([(‘0’, 0), (‘1’, 1), (‘2’, 2)])
Option C. An exception is thrown
Option D. ‘ ‘
True Answer B

Explanation :
The line of code a=collections.OrderedDict() generates a dictionary satisfying the conditions given within the parenthesis and in an ascending order of the keys.

What will be the output of the following Python code?

>>> import collections

>>> a=collections.OrderedDict((str(x),x) for x in range(3)) 

>>> a

Question No# : 12 out of 20



What will be the output of the following Python code?

  x=[[1],[2]]  print(" ".join(list(map(str,x))))

Option A. [1] [2]
Option B. [49] [50]
Option C. Syntax error
Option D. [[1]] [[2]]
True Answer A

Explanation :
The elements 1 and 2 are first put into separate lists and then combined with a space in between using the join attribute.

What will be the output of the following Python code?

  x=[[1],[2]]  print(" ".join(list(map(str,x))))

Question No# : 13 out of 20



What will be the output of the following Python code?

=[1, 0, 2, 0, 'hello', '', []]

list(filter(bool, l))
      

Option A. Error
Option B. [1, 0, 2, 0, ‘hello’, ”, []]
Option C. [1, 0, 2, ‘hello’, ”, []]
Option D. [1, 2, ‘hello’]
True Answer D

Explanation :
The code shown above returns a new list containing only those elements of the list l which do not amount to zero. Hence the output is: [1, 2, ‘hello’].

What will be the output of the following Python code?

=[1, 0, 2, 0, 'hello', '', []]

list(filter(bool, l))
      

Question No# : 14 out of 20



Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

Option A. d.delete(“john”:40)
Option B. d.delete(“john”)
Option C. del d[“john”]
Option D. del d(“john”:40)
True Answer C

Explanation :
Execute in the shell to verify.

Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

Question No# : 15 out of 20



What will be the output of the following Python code?

>>> import collections

>>> b=dict()  >>> b=collections.defaultdict(lambda: 7) 

>>> b[4]

Option A. 4
Option B. 0
Option C. An exception is thrown
Option D. 7
True Answer D

Explanation :
The statement a=collections.defaultdict(lambda: x) gives the default value of x even if the keys don’t exist in the dictionary.

What will be the output of the following Python code?

>>> import collections

>>> b=dict()  >>> b=collections.defaultdict(lambda: 7) 

>>> b[4]

Question No# : 16 out of 20



What will be the output of the following Python code snippet?

print([i.lower() for i in "HELLO"])

Option A. [‘h’, ‘e’, ‘l’, ‘l’, ‘o’]
Option B. ‘hello’
Option C. [‘hello’]
Option D. hello
True Answer A

Explanation :
We are iterating over each letter in the string.

What will be the output of the following Python code snippet?

print([i.lower() for i in "HELLO"])

Question No# : 17 out of 20



What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

  b={4:"D",5:"E"}  a.update(b) 

print(a)

Option A. {1: ‘A’, 2: ‘B’, 3: ‘C’}
Option B. Method update() doesn’t exist for dictionaries
Option C. {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
Option D. {4: ‘D’, 5: ‘E’}
True Answer C

Explanation :
update() method adds dictionary b’s key-value pairs to dictionary a. Execute in python shell to verify.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

  b={4:"D",5:"E"}  a.update(b) 

print(a)

Question No# : 18 out of 20



What is the syntax of the following Python code?

>>> a=frozenset(set([5,6,7]))  >>> a

Option A. {5,6,7}
Option B. frozenset({5,6,7})
Option C. Error, not possible to convert set into frozenset
Option D. Syntax error
True Answer B

Explanation :
The above piece of code is the correct syntax for creating a frozenset.

What is the syntax of the following Python code?

>>> a=frozenset(set([5,6,7]))  >>> a

Question No# : 19 out of 20



What will be the output of the following Python code?

>>> a={5,6,7,8}

>>> b={7,8,9,10} 

>>> len(a+b)

Option A. 8
Option B. Error, unsupported operand ‘+’ for sets
Option C. 6
Option D. Nothing is displayed
True Answer B

Explanation :
Duplicate elements in a+b is eliminated and the length of a+b is computed.

What will be the output of the following Python code?

>>> a={5,6,7,8}

>>> b={7,8,9,10} 

>>> len(a+b)

Question No# : 20 out of 20




CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad