MCQ : Sequence data types in python For NIELIT O Level Exam

Sequence data types in python For NIELIT O Level Exam

00:00:00

Write a list comprehension for number and its cube for:

l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

Option A. [x**3 for x in l]
Option B. [x^3 for x in l]
Option C. [x**3 in l]
Option D. [x^3 in l]
True Answer A

Explanation :
The list comprehension to print a list of cube of the numbers for the given list is: [x**3 for x in l].

Write a list comprehension for number and its cube for:

l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

Question No# : 01 out of 20



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

s1={3, 4}

  s2={1, 2}  s3=set()  i=0  j=0  for i in s1:      for j in s2:          s3.add((i,j))          i+=1          j+=1 

print(s3)

Option A. {(3, 4), (1, 2)}
Option B. Error
Option C. {(4, 2), (3, 1), (4, 1), (5, 2)}
Option D. {(3, 1), (4, 2)}
True Answer C

Explanation :
The code shown above finds the Cartesian product of the two sets, s1 and s2. The Cartesian product of these two sets is stored in a third set, that is, s3. Hence the output of this code is: {(4, 2), (3, 1), (4, 1), (5, 2)}.

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

s1={3, 4}

  s2={1, 2}  s3=set()  i=0  j=0  for i in s1:      for j in s2:          s3.add((i,j))          i+=1          j+=1 

print(s3)

Question No# : 02 out of 20



What will be the output of the following Python list comprehension?

[j for i in range(2,8) for j in range(i*2, 50, i)]

Option A. A list of prime numbers up to 50
Option B. A list of numbers divisible by 2, up to 50
Option C. A list of non prime numbers, up to 50
Option D. Error
True Answer C

Explanation :
The list comprehension shown above returns a list of non-prime numbers up to 50. The logic behind this is that the square root of 50 is almost equal to 7. Hence all the multiples of 2-7 are not prime in this range.

What will be the output of the following Python list comprehension?

[j for i in range(2,8) for j in range(i*2, 50, i)]

Question No# : 03 out of 20



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

print([if i%2==0: i; else: i+1; for i in range(4)])

Option A. [0, 2, 2, 4]
Option B. [1, 1, 3, 3]
Option C. error
Option D. none of the mentioned
True Answer C

Explanation :
Syntax error.

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

print([if i%2==0: i; else: i+1; for i in range(4)])

Question No# : 04 out of 20



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

 

  1.   d = {"john":40, "peter":45}
  2.   print(list(d.keys()))

 

Option A. [“john”, “peter”]
Option B. [“john”:40, “peter”:45]
Option C. (“john”, “peter”)
Option D. (“john”:40, “peter”:45)
True Answer A

Explanation :
The output of the code shown above is a list containing only keys of the dictionary d, in the form of a list.

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

 

  1.   d = {"john":40, "peter":45}
  2.   print(list(d.keys()))

 

Question No# : 05 out of 20



What will be the output of the following Python code?

  A = [[1, 2, 3],       [4, 5, 6],       [7, 8, 9]]  [A[i][i] for i in range(len(A))]

Option A. [1, 5, 9]
Option B. [3, 5, 7]
Option C. [4, 5, 6]
Option D. [2, 5, 8]
True Answer A

Explanation :
We can also perform tasks like pulling out a diagonal. The expression shown above uses range to generate the list of offsets and the indices with the row and column the same, picking out A[0][0], then A[1][1] and so on. Hence the output of the code is: [1, 5, 9].

What will be the output of the following Python code?

  A = [[1, 2, 3],       [4, 5, 6],       [7, 8, 9]]  [A[i][i] for i in range(len(A))]

Question No# : 06 out of 20



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

a = {}

  a[1] = 1  a['1'] = 2  a[1]=a[1]+1  count = 0  for i in a: 

count += a[i]

print(count)

Option A. 1
Option B. 2
Option C. 4
Option D. Error, the keys can’t be a mixture of letters and numbers
True Answer C

Explanation :
The above piece of code basically finds the sum of the values of keys.

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

a = {}

  a[1] = 1  a['1'] = 2  a[1]=a[1]+1  count = 0  for i in a: 

count += a[i]

print(count)

Question No# : 07 out of 20



What will be the output of the following Python code?

>>> a={3,4,5}  >>> b={5,6,7}  >>> a|b

Option A. Invalid operation
Option B. {3, 4, 5, 6, 7}
Option C. {5}
Option D. {3,4,6,7}
True Answer D

Explanation :
The operation in the above piece of code is union operation. This operation produces a set of elements in both set a and set b.

What will be the output of the following Python code?

>>> a={3,4,5}  >>> b={5,6,7}  >>> a|b

Question No# : 08 out of 20



What will be the output of the following Python code?

s=set()

type(s)

Option A. <’set’>
Option B. <class ‘set’>
Option C. set
Option D. class set
True Answer B

Explanation :
When we find the type of a set, the output returned is: .

What will be the output of the following Python code?

s=set()

type(s)

Question No# : 09 out of 20



What will be the output of the following Python code?

>>> a={3,4,5}

>>> a.update([1,2,3]) 

>>> a

Option A. Error, no method called update for set data type
Option B. {1, 2, 3, 4, 5}
Option C. Error, list can’t be added to set
Option D. Error, duplicate item present in list
True Answer B

Explanation :
The method update adds elements to a set.

What will be the output of the following Python code?

>>> a={3,4,5}

>>> a.update([1,2,3]) 

>>> a

Question No# : 10 out of 20



What will be the output of the following Python code?

  a=165  b=sum(list(map(int,str(a))))  print(b)

Option A. 561
Option B. 5
Option C. 12
Option D. Syntax error
True Answer C

Explanation :
First, map converts the number to string and then places the individual digits in a list. Then, sum finds the sum of the digits in the list. The code basically finds the sum of digits in the number.

What will be the output of the following Python code?

  a=165  b=sum(list(map(int,str(a))))  print(b)

Question No# : 11 out of 20



Which of the following isn’t true about dictionary keys?

Option A. More than one key isn’t allowed
Option B. Keys must be immutable
Option C. Keys must be integers
Option D. When duplicate keys encountered, the last assignment wins
True Answer C

Explanation :
Keys of a dictionary may be any data type that is immutable.

Which of the following isn’t true about dictionary keys?

Question No# : 12 out of 20



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

  a = {}  a[1] = 1  a['1'] = 2  a[1.0]=4  count = 0  for i in a:      count += a[i]  print(count)

Option A. An exception is thrown
Option B. 3
Option C. 6
Option D. 2
True Answer C

Explanation :
The value of key 1 is 4 since 1 and 1.0 are the same. Then, the function count() gives the sum of all the values of the keys (2+4).

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

  a = {}  a[1] = 1  a['1'] = 2  a[1.0]=4  count = 0  for i in a:      count += a[i]  print(count)

Question No# : 13 out of 20



Which of the following statements create a dictionary?

Option A. d = {}
Option B. d = {“john”:40, “peter”:45}
Option C. d = {40:”john”, 45:”peter”}
Option D. All of the mentioned
True Answer D

Explanation :
Dictionaries are created by specifying keys and values.

Which of the following statements create a dictionary?

Question No# : 14 out of 20



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

>>> import collections  >>> a=collections.Counter([3,3,4,5])  >>> b=collections.Counter([3,4,4,5,5,5])  >>> a&b

Option A. Counter({3: 12, 4: 1, 5: 1})
Option B. Counter({3: 1, 4: 1, 5: 1})
Option C. Counter({4: 2})
Option D. Counter({5: 1})
True Answer B

Explanation :
a&b returns the pair of keys and the lowest recurring value.

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

>>> import collections  >>> a=collections.Counter([3,3,4,5])  >>> b=collections.Counter([3,4,4,5,5,5])  >>> a&b

Question No# : 15 out of 20



What will be the output of the following Python code?

>>> a=dict()

>>> a[1]

Option A. An exception is thrown since the dictionary is empty
Option B. ‘ ‘
Option C. 1
Option D. 0
True Answer A

Explanation :
The values of a dictionary can be accessed through the keys only if the keys exist in the dictionary.

What will be the output of the following Python code?

>>> a=dict()

>>> a[1]

Question No# : 16 out of 20



Which of the following commands will create a list?

Option A. list1 = list()
Option B. list1 = []
Option C. list1 = list([1, 2, 3])
Option D. all of the mentioned
True Answer D

Explanation :
Execute in the shell to verify

Which of the following commands will create a list?

Question No# : 17 out of 20



What will be the output of the following Python code?

  1. class Name:
  2.         def __init__(self, firstName, mi, lastName):
  3.             self.firstName = firstName
  4.             self.mi = mi
  5.             self.lastName = lastName
  6.      
  7.     firstName = "John"
  8.     name = Name(firstName, 'F', "Smith")
  9.     firstName = "Peter"
  10.     name.lastName = "Pan"
  11.     print(name.firstName, name.lastName)

Option A. Peter Pan
Option B. John Pan
Option C. Peter Smith
Option D. John Smith
True Answer B

Explanation :
Execute in the shell to verify.

What will be the output of the following Python code?

  1. class Name:
  2.         def __init__(self, firstName, mi, lastName):
  3.             self.firstName = firstName
  4.             self.mi = mi
  5.             self.lastName = lastName
  6.      
  7.     firstName = "John"
  8.     name = Name(firstName, 'F', "Smith")
  9.     firstName = "Peter"
  10.     name.lastName = "Pan"
  11.     print(name.firstName, name.lastName)

Question No# : 18 out of 20



What will be the output of the following Python code?

import copy  a=[10,23,56,[78]]  b=copy.deepcopy(a)  a[3][0]=95  a[1]=34  print(b)

Option A. [10,34,56,[95]]
Option B. [10,23,56,[78]]
Option C. [10,23,56,[95]]
Option D. [10,34,56,[78]]
True Answer B

Explanation :
The above copy is deepcopy. Any change made in the original list isn’t reflected.

What will be the output of the following Python code?

import copy  a=[10,23,56,[78]]  b=copy.deepcopy(a)  a[3][0]=95  a[1]=34  print(b)

Question No# : 19 out of 20



Bundling two values together into one can be considered as

Option A. Pair
Option B. Triplet
Option C. single
Option D. quadrat
True Answer A

Explanation :
Bundling two values together into one can be considered as a pair

Bundling two values together into one can be considered as

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