Get Latest Exam Updates, Free Study materials and Tips

Q.1:

Which of the following would give an error?

A) list1=[] B) list1=[]*3
C) list1=[2,8,7] D) None of the above
Q.2:

Which of the following is True regarding lists in Python?

A) Lists are immutable. B) Size of the lists must be specified before its initialization
C) Elements of lists are stored in contagious memory location. D) size(list1) command is used to find the size of lists.
Q.3:

What will be the output of below Python code?

list1=[8,0,9,5]

print(list1[::-1])

A) [5,9,0,8] B) [8,0,9]
C) [8,0,9,5] D) [0,9,5]
Q.4:

Which of the following will give output as [23,2,9,75] ?

If list1=[6,23,3,2,0,9,8,75]

A) print(list1[1:7:2]) B) print(list1[0:7:2])
C) print(list1[1:8:2]) D) print(list1[0:8:2])
Q.5:

The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95]. How can the student’s average mark be calculated?

A) print(avg(list1)) B) print(sum(list1)/len(list1))
C) print(sum(list1)/sizeof(list1)) D) print(total(list1)/len(list1))
Q.6:

What will be the output of following Python code?

list1=["Python","Java","c","C","C++"]

print(min(list1))

A) c B) C++
C) C D) min function cannot be used on string elements
Q.7:

The elements of a list are arranged in descending order. Which of the following two will give same outputs?

i. print(list_name.sort())

ii. print(max(list_name))

iii. print(list_name.reverse())

iv. print(list_name[-1])

A) i, ii B) i, iii
C) ii, iii D) iii, iv
Q.8:

What will be the result after the execution of above Python code ?

list1=[3,2,5,7,3,6]

list1.pop(3)

print(list1)

A) [3,2,5,3,6] B) [2,5,7,3,6]
C) [2,5,7,6] D) [3,2,5,7,3,6]
Q.9:

What will be the output of below Python code?

list1=[1,3,5,2,4,6,2]

list1.remove(2)

print(sum(list1))

A) 18 B) 19
C) 21 D) 22
Q.10:

What will be the output of below Python code ?

list1=["tom","mary","simon"]

list1.insert(5,8)

print(list1)

A) ["tom", "mary", "simon", 5] B) ["tom", "mary", "simon", 8]
C) [8, "tom", "mary", "simon"] D) Error
Q.11:

Which of the following is a Python tuple ?

A) [1, 2, 3] B) (1, 2, 3)
C) {1, 2, 3} D) {}
Q.12:

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

A) print(t[3]) B) t[3] = 45
C) print(max(t)) D) print(len(t))
Q.13:

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:3]

A) (1, 2) B) (1, 2, 4)
C) (2, 4) D) (2, 4, 3)
Q.14:

What will be the output of the following Python code?

>>>t = (1, 2, 4, 3, 8, 9)

>>>[t[i] for i in range(0, len(t), 2)]

A) [2, 3, 9] B) [1, 2, 4, 3, 8, 9]
C) [1, 4, 8] D) (1, 4, 8)
Q.15:

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:-1]

A) (1, 2) B) (1, 2, 4)
C) (2, 4) D) (2, 4, 3)
Q.16:

What will be the output of the following Python code ?

d = {"john":40, "peter":45}

d["john"]

A) 40 B) 45
C) “john” D) “peter”
Q.17:

What will be the output of the following Python code?

>>>t = (1, 2)

>>>2 * t

A) (1, 2, 1, 2) B) [1, 2, 1, 2]
C) (1, 1, 2, 2) D) [1, 1, 2, 2]
Q.18:

What will be the output of the following Python code?

>>>t1 = (1, 2, 4, 3)

>>>t2 = (1, 2, 3, 4)

>>>t1 < t2

A) True B) False
C) Error D) None
Q.19:

What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

A) 1 B) 2
C) 5 D) Error
Q.20:

What will be the output of the following Python code ?

numberGames = {}

numberGames[(1,2,4)] = 8

numberGames[(4,2,1)] = 10

numberGames[(1,2)] = 12

sum = 0

for k in numberGames:

sum += numberGames[k]

print len(numberGames) + sum

A) 30 B) 24
C) 33 D) 12
Q.21:

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

A) { } B) set()
C) [ ]. D) ( )
Q.22:

What is the output of the following piece of code when executed in the python shell?

a={1,2,3} 

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

a

A) {2,3} B) Error, duplicate item present in list
C) Error, no method called intersection_update for set data type D) {1,4,5}
Q.23:

Which of the following lines of code will result in an error ?

A) s={abs} B) s={4, ‘abc’, (1,2)}
C) s={2, 2.2, 3, ‘xyz’} D) s={san}
Q.24:

What is the output of the code shown below ?

s=set([1, 2, 3])

s.union([4, 5])

s|([4, 5])

A) {1, 2, 3, 4, 5}{1, 2, 3, 4, 5} B) Error{1, 2, 3, 4, 5}
C) {1, 2, 3, 4, 5}Error D) ErrorError
Q.25:

What is the output of the line of code shown below,

if s1= {1, 2, 3}?

s1.issubset(s1)

A) True B) Error
C) No output D) False
Q.26:

Which of these about a frozenset is not true?

A) Mutable data type B) Allows duplicate values
C) Data type with unordered values D) Immutable data type
Q.27:

Is the following Python code valid?

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

>>> a

>>> a.add(5)

A) Yes, now a is {5,5,6,7} B) No, frozen set is immutable
C) No, invalid syntax for add method D) Yes, now a is {5,6,7}
Q.28:

What is the syntax of the following Python code ?

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

>>> a

A) {5,6,7} B) frozenset({5,6,7})
C) Error, not possible to convert set into frozenset D) Syntax error
Q.29:

Set members must not be hashable.

A) True B) False
Q.30:

What will be the output of the following Python code?

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

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

>>> a

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

What will be the output of the following Python code?

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

>>> b=a

>>> b.remove(3)

>>> a

A) {1,2,3} B) Error, copying of sets isn’t allowed
C) {1,2} D) Error, invalid syntax for remove
Q.32:

What will be the output of the following Python code?

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

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

>>> a

A) {2,3} B) Error, duplicate item present in list
C) Error, no method called intersection_update for set data type D) {1,4,5}
Q.33:

What will be the output of the following Python code?

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

>>> b=a.copy()

>>> b.add(4)

>>> a

A) {1,2,3} B) Error, invalid syntax for add
C) {1,2,3,4} D) Error, copying of sets isn’t allowed
Q.34:

What will be the output of the following Python code?

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

>>> b=a.add(4)

>>> b

A) 0 B) {1,2,3,4}
C) {1,2,3} D) Nothing is printed
Q.35:

What will be the output of the following Python code?

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

>>> b=frozenset([3,4,5])

>>> a-b

A) {1,2} B) Error as difference between a set and frozenset can’t be found out
C) Error as unsupported operand type for set data type D) frozenset({1,2})
Q.36:

What will be the output of the following Python code?

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

>>> {x*2 for x in a|{4,5}}

A) {2,4,6} B) Error, set comprehensions aren’t allowed
C) {8, 2, 10, 4, 6} D) {8,10}
Q.37:

What will be the output of the following Python code?

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

>>> sum(a,5)

A) 5 B) 23
C) 18 D) Invalid syntax for sum method, too many arguments
Q.38:

What will be the output of the following Python code?

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

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

>>> len(a+b)

A) 8 B) Error, unsupported operand ‘+’ for sets
C) 6 D) Nothing is displayed
Q.39:

What will be the output of the following Python code?

a={1,2,3}

b={1,2,3}

c=a.issubset(b)

print(c)

A) True B) Error, no method called issubset() exists
C) Syntax error for issubset() method D) False
Q.40:

Is the following Python code valid ?

a={1,2,3}

b={1,2,3,4}

c=a.issuperset(b)

print(c)

A) False B) True
C) Syntax error for issuperset() method D) Error, no method called issuperset() exists
Q.41:

Which line of code correctly initializes ‘grapes’ into the fruits dictionary?
fruits = {'apples': 1, 'bananas': 4, 'pears': 17, 'oranges': 14}

A) fruit['grapes'] B) fruit['grapes'] = 15
C) none D) insert 'grapes' in fruit
Answer & Explanation
Q.42:

What prints when the following code is run?
names = {'Janice': 5, 'Emily': 3, 'John': 7, 'Eleanor': 2}
list_o_names = []
for name in names:
if names[name] > 5:
list_o_names.append(name)
print(list_o_names

A) ['Janice', 'John'] B) ['Janice', 'Emily', 'Eleanor']
C) ['John'] D) none
Answer & Explanation
Q.43:

What does the following code print now that it has been updated?
names = {'Janice': 5, 'Emily': 3, 'John': 7, 'Eleanor': 2}
list_o_names = []
names['Emily'] += 10
names['Erik'] = 22
for name in names:
if names[name] > 5:
list_o_names.append(name)
print(list_o_names)

A) ['Emily', 'John', 'Erik'] B) ['Janice', 'Emily', 'John']
C) ['Janice', 'John', 'Erik'] D) cannot be determined
Answer & Explanation
Q.44:

What is the value of counter after the code is run to completion?
phrase = "Cheese in Philadelphia is extraordinary according to Erik"
counter = 0 letters = {} for word in phrase.split(): for letter in word: letter = letter.lower() if letter not in letters.keys(): letters[letter] = 0 letters[letter] += 1 for key in letters.keys(): if letters[key] > 2: counter += 1

A) 5 B) 10
C) 9 D) 8
Answer & Explanation
Q.45:

Which line of code correctly grabs the value of the key ‘apples’?
fruits = {'bananas': 7, 'apples': 4, 'grapes': 19, 'pears': 4}

A) fruits.get(apples) B) fruits.get('apples', 0)
C) fruits.get('apple') D) fruits.get(apples, 0)
Answer & Explanation
Q.46:

What value is printed once the code is run?

word = 'brontosaurus'
diction = {}
for letter in word:
if letter not in diction.keys():
diction[letter] = 0
diction[letter] += 1
print(diction.get('o', 0) + 4)

A) 10 B) 4
C) 8 D) 6
Answer & Explanation
Q.47:

What order do the keys print in after the following code is run? (Select all that apply)
counts = {'chuck' : 1, 'annie' : 42, 'jan' : 100}/
for key in counts:
print(key, counts[key])

A) jan, chuck, annie B) chuck, annie, jan
C) annie, chuck, jan D) All of these
Answer & Explanation
Q.48:

Which of the following is the correct way to initialize the string module?

A) import String B) import string
C) import string module D) none
Answer & Explanation
Q.49:

True or false? Python treats the words “Exciting” and “exciting” as the same word.

A)True B) False
Answer & Explanation
Q.50:

Which line of code correctly uses the .translate() method?

A) line.translate(str.maketrans(fromstr, tostr, deletestr)) B) line.translate(fromstr, tostr, deletestr)
C) line.translate(str.translate(fromstr, tostr, deletestr)) D) none
Answer & Explanation
Q.51:

NumPY stands for?

A) Numbering Python B) Number In Python
C) Numerical Python D) None Of the above
Answer & Explanation
Q.52:

NumPy is often used along with packages like?

A) Node.js B) Matplotlib
C) SciPy D) Both B and C
Answer & Explanation
Q.53:

The most important object defined in NumPy is an N-dimensional array type called?

A) ndarray B) narray
C) nd_array D) darray
Answer & Explanation
Q.54:

What will be output for the following code?
import numpy as np
a = np.array([1,2,3])
print a

A) [[1, 2, 3]] B) [1]
C) [1, 2, 3] D) Error
Answer & Explanation
Q.55:

What will be output for the following code?
import numpy as np
a = np.array([1, 2, 3], dtype = complex) print a

A) [[ 1.+0.j, 2.+0.j, 3.+0.j]] B) [ 1.+0.j]
C) Error D) [ 1.+0.j, 2.+0.j, 3.+0.j]
Answer & Explanation
Q.56:

Which of the following statement is false?

A) ndarray is also known as the axis array. B) ndarray.dataitemSize is the buffer containing the actual elements of the array.
C) NumPy main object is the homogeneous multidimensional array D) In Numpy, dimensions are called axes
Answer & Explanation
Q.57:

If a dimension is given as ____ in a reshaping operation, the other dimensions are automatically calculated.

A) Zero B) One
C) Negative one D) Infinite
Answer & Explanation
Q.58:

Which of the following sets the size of the buffer used in ufuncs?

A) bufsize(size) B) setsize(size)
C) setbufsize(size) D) size(size)
Answer & Explanation
Q.59:

What will be output for the following code?

import numpy as np
dt = dt = np.dtype('i4')
print dt

A) int32 B) int64
C) int128 D) int16
Answer & Explanation
Q.60:

Each built-in data type has a character code that uniquely identifies it.What is meaning of code "M"? r

A) timedelta B) datetime
C) objects D) Unicode
Answer & Explanation
Q.61:

The output of the code shown below is:

odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
  if odd(i):
  continue
else:
  break

A) [0, 2, 4, 6, 8, 10] B) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
C) [1, 3, 5, 7, 9] D) Error
Answer & Explanation
Q.62:

What is the output of the code shown below?

f=lambda x:bool(x%2)
print(f(20), f(21))

A) False True B) False False
C) True True D) True False
Answer & Explanation
Q.63:

What is the output of the code shown below?

import functools
l=[1,2,3,4]
print(functools.reduce(lambda x,y:x*y,l))

A) Error B) 10
C) 24 D) No output
Answer & Explanation
Q.64:

What is the output of the code shown?

l=[1, -2, -3, 4, 5]
def f1(x):
  return x<2
m1=filter(f1, l)
print(list(m1))

A) [1, 4, 5 ] B) Error
C) [-2, -3] D) [1, -2, -3]
Answer & Explanation
Q.65:

What is the output of the code shown below?

l=[-2, 4]
m=map(lambda x:x*2, l)
print(m)

A) [-4, 16] B) Address of m
C) Error D) -4
16
Answer & Explanation
Q.66:

What is the output of the following code?

l=[1, -2, -3, 4, 5]
def f1(x):
return x<-1 m1=map(f1, l)
print(list(m1))

A)[False, False, False, False, False] B) [False, True, True, False, False]
C) [True, False, False, True, True] D) [True, False, False, True, True]
Answer & Explanation
Q.67:

What is the output of the code shown?

l=[1, 2, 3, 4, 5]
m=map(lambda x:2**x, l)
print(list(m))

A) [1, 4, 9, 16, 25 ] B) [2, 4, 8, 16, 32 ]
C) [1, 0, 1, 0, 1] D) Error
Answer & Explanation
Q.68:

What is the output of the code shown?

import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)

A) Error B) Address of m
C) 1 D) 5
Answer & Explanation
Q.69:

What is the output of the code shown below?

l=[n for n in range(5)]
f=lambda x:bool(x%2)
print(f(3), f(1))
for i in range(len(l)):
  if f(l[i]):
  del l[i]
  print(i)

A) True True
1
2
Error
B) False False
1
2
C) True False
1
2
Error
D) False True
1
2
Answer & Explanation
Q.70:

What is the output of the code shown?

m=reduce(lambda x: x-3 in range(4, 10))
print(list(m))

A) [1, 2, 3, 4, 5, 6, 7] B) No output
C) [1, 2, 3, 4, 5, 6] D) Error
Answer & Explanation
Q.1:

Which of the following would give an error?

A) list1=[] B) list1=[]*3
C) list1=[2,8,7] D) None of the above
Q.2:

Which of the following is True regarding lists in Python?

A) Lists are immutable. B) Size of the lists must be specified before its initialization
C) Elements of lists are stored in contagious memory location. D) size(list1) command is used to find the size of lists.
Q.3:

What will be the output of below Python code?

list1=[8,0,9,5]

print(list1[::-1])

A) [5,9,0,8] B) [8,0,9]
C) [8,0,9,5] D) [0,9,5]
Q.4:

Which of the following will give output as [23,2,9,75] ?

If list1=[6,23,3,2,0,9,8,75]

A) print(list1[1:7:2]) B) print(list1[0:7:2])
C) print(list1[1:8:2]) D) print(list1[0:8:2])
Q.5:

The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95]. How can the student’s average mark be calculated?

A) print(avg(list1)) B) print(sum(list1)/len(list1))
C) print(sum(list1)/sizeof(list1)) D) print(total(list1)/len(list1))
Q.6:

What will be the output of following Python code?

list1=["Python","Java","c","C","C++"]

print(min(list1))

A) c B) C++
C) C D) min function cannot be used on string elements
Q.7:

The elements of a list are arranged in descending order. Which of the following two will give same outputs?

i. print(list_name.sort())

ii. print(max(list_name))

iii. print(list_name.reverse())

iv. print(list_name[-1])

A) i, ii B) i, iii
C) ii, iii D) iii, iv
Q.8:

What will be the result after the execution of above Python code ?

list1=[3,2,5,7,3,6]

list1.pop(3)

print(list1)

A) [3,2,5,3,6] B) [2,5,7,3,6]
C) [2,5,7,6] D) [3,2,5,7,3,6]
Q.9:

What will be the output of below Python code?

list1=[1,3,5,2,4,6,2]

list1.remove(2)

print(sum(list1))

A) 18 B) 19
C) 21 D) 22
Q.10:

What will be the output of below Python code ?

list1=["tom","mary","simon"]

list1.insert(5,8)

print(list1)

A) ["tom", "mary", "simon", 5] B) ["tom", "mary", "simon", 8]
C) [8, "tom", "mary", "simon"] D) Error
Q.11:

Which of the following is a Python tuple ?

A) [1, 2, 3] B) (1, 2, 3)
C) {1, 2, 3} D) {}
Q.12:

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

A) print(t[3]) B) t[3] = 45
C) print(max(t)) D) print(len(t))
Q.13:

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:3]

A) (1, 2) B) (1, 2, 4)
C) (2, 4) D) (2, 4, 3)
Q.14:

What will be the output of the following Python code?

>>>t = (1, 2, 4, 3, 8, 9)

>>>[t[i] for i in range(0, len(t), 2)]

A) [2, 3, 9] B) [1, 2, 4, 3, 8, 9]
C) [1, 4, 8] D) (1, 4, 8)
Q.15:

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:-1]

A) (1, 2) B) (1, 2, 4)
C) (2, 4) D) (2, 4, 3)
Q.16:

What will be the output of the following Python code ?

d = {"john":40, "peter":45}

d["john"]

A) 40 B) 45
C) “john” D) “peter”
Q.17:

What will be the output of the following Python code?

>>>t = (1, 2)

>>>2 * t

A) (1, 2, 1, 2) B) [1, 2, 1, 2]
C) (1, 1, 2, 2) D) [1, 1, 2, 2]
Q.18:

What will be the output of the following Python code?

>>>t1 = (1, 2, 4, 3)

>>>t2 = (1, 2, 3, 4)

>>>t1 < t2

A) True B) False
C) Error D) None
Q.19:

What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

A) 1 B) 2
C) 5 D) Error
Q.20:

What will be the output of the following Python code ?

numberGames = {}

numberGames[(1,2,4)] = 8

numberGames[(4,2,1)] = 10

numberGames[(1,2)] = 12

sum = 0

for k in numberGames:

sum += numberGames[k]

print len(numberGames) + sum

A) 30 B) 24
C) 33 D) 12
Q.21:

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

A) { } B) set()
C) [ ]. D) ( )
Q.22:

What is the output of the following piece of code when executed in the python shell?

a={1,2,3} 

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

a

A) {2,3} B) Error, duplicate item present in list
C) Error, no method called intersection_update for set data type D) {1,4,5}
Q.23:

Which of the following lines of code will result in an error ?

A) s={abs} B) s={4, ‘abc’, (1,2)}
C) s={2, 2.2, 3, ‘xyz’} D) s={san}
Q.24:

What is the output of the code shown below ?

s=set([1, 2, 3])

s.union([4, 5])

s|([4, 5])

A) {1, 2, 3, 4, 5}{1, 2, 3, 4, 5} B) Error{1, 2, 3, 4, 5}
C) {1, 2, 3, 4, 5}Error D) ErrorError
Q.25:

What is the output of the line of code shown below,

if s1= {1, 2, 3}?

s1.issubset(s1)

A) True B) Error
C) No output D) False
Q.26:

Which of these about a frozenset is not true?

A) Mutable data type B) Allows duplicate values
C) Data type with unordered values D) Immutable data type
Q.27:

Is the following Python code valid?

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

>>> a

>>> a.add(5)

A) Yes, now a is {5,5,6,7} B) No, frozen set is immutable
C) No, invalid syntax for add method D) Yes, now a is {5,6,7}
Q.28:

What is the syntax of the following Python code ?

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

>>> a

A) {5,6,7} B) frozenset({5,6,7})
C) Error, not possible to convert set into frozenset D) Syntax error
Q.29:

Set members must not be hashable.

A) True B) False
Q.30:

What will be the output of the following Python code?

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

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

>>> a

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

What will be the output of the following Python code?

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

>>> b=a

>>> b.remove(3)

>>> a

A) {1,2,3} B) Error, copying of sets isn’t allowed
C) {1,2} D) Error, invalid syntax for remove
Q.32:

What will be the output of the following Python code?

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

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

>>> a

A) {2,3} B) Error, duplicate item present in list
C) Error, no method called intersection_update for set data type D) {1,4,5}
Q.33:

What will be the output of the following Python code?

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

>>> b=a.copy()

>>> b.add(4)

>>> a

A) {1,2,3} B) Error, invalid syntax for add
C) {1,2,3,4} D) Error, copying of sets isn’t allowed
Q.34:

What will be the output of the following Python code?

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

>>> b=a.add(4)

>>> b

A) 0 B) {1,2,3,4}
C) {1,2,3} D) Nothing is printed
Q.35:

What will be the output of the following Python code?

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

>>> b=frozenset([3,4,5])

>>> a-b

A) {1,2} B) Error as difference between a set and frozenset can’t be found out
C) Error as unsupported operand type for set data type D) frozenset({1,2})
Q.36:

What will be the output of the following Python code?

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

>>> {x*2 for x in a|{4,5}}

A) {2,4,6} B) Error, set comprehensions aren’t allowed
C) {8, 2, 10, 4, 6} D) {8,10}
Q.37:

What will be the output of the following Python code?

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

>>> sum(a,5)

A) 5 B) 23
C) 18 D) Invalid syntax for sum method, too many arguments
Q.38:

What will be the output of the following Python code?

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

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

>>> len(a+b)

A) 8 B) Error, unsupported operand ‘+’ for sets
C) 6 D) Nothing is displayed
Q.39:

What will be the output of the following Python code?

a={1,2,3}

b={1,2,3}

c=a.issubset(b)

print(c)

A) True B) Error, no method called issubset() exists
C) Syntax error for issubset() method D) False
Q.40:

Is the following Python code valid ?

a={1,2,3}

b={1,2,3,4}

c=a.issuperset(b)

print(c)

A) False B) True
C) Syntax error for issuperset() method D) Error, no method called issuperset() exists
Q.41:

Which line of code correctly initializes ‘grapes’ into the fruits dictionary?
fruits = {'apples': 1, 'bananas': 4, 'pears': 17, 'oranges': 14}

A) fruit['grapes'] B) fruit['grapes'] = 15
C) none D) insert 'grapes' in fruit
Answer & Explanation
Q.42:

What prints when the following code is run?
names = {'Janice': 5, 'Emily': 3, 'John': 7, 'Eleanor': 2}
list_o_names = []
for name in names:
if names[name] > 5:
list_o_names.append(name)
print(list_o_names

A) ['Janice', 'John'] B) ['Janice', 'Emily', 'Eleanor']
C) ['John'] D) none
Answer & Explanation
Q.43:

What does the following code print now that it has been updated?
names = {'Janice': 5, 'Emily': 3, 'John': 7, 'Eleanor': 2}
list_o_names = []
names['Emily'] += 10
names['Erik'] = 22
for name in names:
if names[name] > 5:
list_o_names.append(name)
print(list_o_names)

A) ['Emily', 'John', 'Erik'] B) ['Janice', 'Emily', 'John']
C) ['Janice', 'John', 'Erik'] D) cannot be determined
Answer & Explanation
Q.44:

What is the value of counter after the code is run to completion?
phrase = "Cheese in Philadelphia is extraordinary according to Erik"
counter = 0 letters = {} for word in phrase.split(): for letter in word: letter = letter.lower() if letter not in letters.keys(): letters[letter] = 0 letters[letter] += 1 for key in letters.keys(): if letters[key] > 2: counter += 1

A) 5 B) 10
C) 9 D) 8
Answer & Explanation
Q.45:

Which line of code correctly grabs the value of the key ‘apples’?
fruits = {'bananas': 7, 'apples': 4, 'grapes': 19, 'pears': 4}

A) fruits.get(apples) B) fruits.get('apples', 0)
C) fruits.get('apple') D) fruits.get(apples, 0)
Answer & Explanation
Q.46:

What value is printed once the code is run?

word = 'brontosaurus'
diction = {}
for letter in word:
if letter not in diction.keys():
diction[letter] = 0
diction[letter] += 1
print(diction.get('o', 0) + 4)

A) 10 B) 4
C) 8 D) 6
Answer & Explanation
Q.47:

What order do the keys print in after the following code is run? (Select all that apply)
counts = {'chuck' : 1, 'annie' : 42, 'jan' : 100}/
for key in counts:
print(key, counts[key])

A) jan, chuck, annie B) chuck, annie, jan
C) annie, chuck, jan D) All of these
Answer & Explanation
Q.48:

Which of the following is the correct way to initialize the string module?

A) import String B) import string
C) import string module D) none
Answer & Explanation
Q.49:

True or false? Python treats the words “Exciting” and “exciting” as the same word.

A)True B) False
Answer & Explanation
Q.50:

Which line of code correctly uses the .translate() method?

A) line.translate(str.maketrans(fromstr, tostr, deletestr)) B) line.translate(fromstr, tostr, deletestr)
C) line.translate(str.translate(fromstr, tostr, deletestr)) D) none
Answer & Explanation
Q.51:

NumPY stands for?

A) Numbering Python B) Number In Python
C) Numerical Python D) None Of the above
Answer & Explanation
Q.52:

NumPy is often used along with packages like?

A) Node.js B) Matplotlib
C) SciPy D) Both B and C
Answer & Explanation
Q.53:

The most important object defined in NumPy is an N-dimensional array type called?

A) ndarray B) narray
C) nd_array D) darray
Answer & Explanation
Q.54:

What will be output for the following code?
import numpy as np
a = np.array([1,2,3])
print a

A) [[1, 2, 3]] B) [1]
C) [1, 2, 3] D) Error
Answer & Explanation
Q.55:

What will be output for the following code?
import numpy as np
a = np.array([1, 2, 3], dtype = complex) print a

A) [[ 1.+0.j, 2.+0.j, 3.+0.j]] B) [ 1.+0.j]
C) Error D) [ 1.+0.j, 2.+0.j, 3.+0.j]
Answer & Explanation
Q.56:

Which of the following statement is false?

A) ndarray is also known as the axis array. B) ndarray.dataitemSize is the buffer containing the actual elements of the array.
C) NumPy main object is the homogeneous multidimensional array D) In Numpy, dimensions are called axes
Answer & Explanation
Q.57:

If a dimension is given as ____ in a reshaping operation, the other dimensions are automatically calculated.

A) Zero B) One
C) Negative one D) Infinite
Answer & Explanation
Q.58:

Which of the following sets the size of the buffer used in ufuncs?

A) bufsize(size) B) setsize(size)
C) setbufsize(size) D) size(size)
Answer & Explanation
Q.59:

What will be output for the following code?

import numpy as np
dt = dt = np.dtype('i4')
print dt

A) int32 B) int64
C) int128 D) int16
Answer & Explanation
Q.60:

Each built-in data type has a character code that uniquely identifies it.What is meaning of code "M"? r

A) timedelta B) datetime
C) objects D) Unicode
Answer & Explanation
Q.61:

The output of the code shown below is:

odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
  if odd(i):
  continue
else:
  break

A) [0, 2, 4, 6, 8, 10] B) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
C) [1, 3, 5, 7, 9] D) Error
Answer & Explanation
Q.62:

What is the output of the code shown below?

f=lambda x:bool(x%2)
print(f(20), f(21))

A) False True B) False False
C) True True D) True False
Answer & Explanation
Q.63:

What is the output of the code shown below?

import functools
l=[1,2,3,4]
print(functools.reduce(lambda x,y:x*y,l))

A) Error B) 10
C) 24 D) No output
Answer & Explanation
Q.64:

What is the output of the code shown?

l=[1, -2, -3, 4, 5]
def f1(x):
  return x<2
m1=filter(f1, l)
print(list(m1))

A) [1, 4, 5 ] B) Error
C) [-2, -3] D) [1, -2, -3]
Answer & Explanation
Q.65:

What is the output of the code shown below?

l=[-2, 4]
m=map(lambda x:x*2, l)
print(m)

A) [-4, 16] B) Address of m
C) Error D) -4
16
Answer & Explanation
Q.66:

What is the output of the following code?

l=[1, -2, -3, 4, 5]
def f1(x):
return x<-1 m1=map(f1, l)
print(list(m1))

A)[False, False, False, False, False] B) [False, True, True, False, False]
C) [True, False, False, True, True] D) [True, False, False, True, True]
Answer & Explanation
Q.67:

What is the output of the code shown?

l=[1, 2, 3, 4, 5]
m=map(lambda x:2**x, l)
print(list(m))

A) [1, 4, 9, 16, 25 ] B) [2, 4, 8, 16, 32 ]
C) [1, 0, 1, 0, 1] D) Error
Answer & Explanation
Q.68:

What is the output of the code shown?

import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)

A) Error B) Address of m
C) 1 D) 5
Answer & Explanation
Q.69:

What is the output of the code shown below?

l=[n for n in range(5)]
f=lambda x:bool(x%2)
print(f(3), f(1))
for i in range(len(l)):
  if f(l[i]):
  del l[i]
  print(i)

A) True True
1
2
Error
B) False False
1
2
C) True False
1
2
Error
D) False True
1
2
Answer & Explanation
Q.70:

What is the output of the code shown?

m=reduce(lambda x: x-3 in range(4, 10))
print(list(m))

A) [1, 2, 3, 4, 5, 6, 7] B) No output
C) [1, 2, 3, 4, 5, 6] D) Error
Answer & Explanation
Q.1:

Which of the following would give an error?

A) list1=[] B) list1=[]*3
C) list1=[2,8,7] D) None of the above
Q.2:

Which of the following is True regarding lists in Python?

A) Lists are immutable. B) Size of the lists must be specified before its initialization
C) Elements of lists are stored in contagious memory location. D) size(list1) command is used to find the size of lists.
Q.3:

What will be the output of below Python code?

list1=[8,0,9,5]

print(list1[::-1])

A) [5,9,0,8] B) [8,0,9]
C) [8,0,9,5] D) [0,9,5]
Q.4:

Which of the following will give output as [23,2,9,75] ?

If list1=[6,23,3,2,0,9,8,75]

A) print(list1[1:7:2]) B) print(list1[0:7:2])
C) print(list1[1:8:2]) D) print(list1[0:8:2])
Q.5:

The marks of a student on 6 subjects are stored in a list, list1=[80,66,94,87,99,95]. How can the student’s average mark be calculated?

A) print(avg(list1)) B) print(sum(list1)/len(list1))
C) print(sum(list1)/sizeof(list1)) D) print(total(list1)/len(list1))
Q.6:

What will be the output of following Python code?

list1=["Python","Java","c","C","C++"]

print(min(list1))

A) c B) C++
C) C D) min function cannot be used on string elements
Q.7:

The elements of a list are arranged in descending order. Which of the following two will give same outputs?

i. print(list_name.sort())

ii. print(max(list_name))

iii. print(list_name.reverse())

iv. print(list_name[-1])

A) i, ii B) i, iii
C) ii, iii D) iii, iv
Q.8:

What will be the result after the execution of above Python code ?

list1=[3,2,5,7,3,6]

list1.pop(3)

print(list1)

A) [3,2,5,3,6] B) [2,5,7,3,6]
C) [2,5,7,6] D) [3,2,5,7,3,6]
Q.9:

What will be the output of below Python code?

list1=[1,3,5,2,4,6,2]

list1.remove(2)

print(sum(list1))

A) 18 B) 19
C) 21 D) 22
Q.10:

What will be the output of below Python code ?

list1=["tom","mary","simon"]

list1.insert(5,8)

print(list1)

A) ["tom", "mary", "simon", 5] B) ["tom", "mary", "simon", 8]
C) [8, "tom", "mary", "simon"] D) Error
Q.11:

Which of the following is a Python tuple ?

A) [1, 2, 3] B) (1, 2, 3)
C) {1, 2, 3} D) {}
Q.12:

Suppose t = (1, 2, 4, 3), which of the following is incorrect?

A) print(t[3]) B) t[3] = 45
C) print(max(t)) D) print(len(t))
Q.13:

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:3]

A) (1, 2) B) (1, 2, 4)
C) (2, 4) D) (2, 4, 3)
Q.14:

What will be the output of the following Python code?

>>>t = (1, 2, 4, 3, 8, 9)

>>>[t[i] for i in range(0, len(t), 2)]

A) [2, 3, 9] B) [1, 2, 4, 3, 8, 9]
C) [1, 4, 8] D) (1, 4, 8)
Q.15:

What will be the output of the following Python code?

>>>t=(1,2,4,3)

>>>t[1:-1]

A) (1, 2) B) (1, 2, 4)
C) (2, 4) D) (2, 4, 3)
Q.16:

What will be the output of the following Python code ?

d = {"john":40, "peter":45}

d["john"]

A) 40 B) 45
C) “john” D) “peter”
Q.17:

What will be the output of the following Python code?

>>>t = (1, 2)

>>>2 * t

A) (1, 2, 1, 2) B) [1, 2, 1, 2]
C) (1, 1, 2, 2) D) [1, 1, 2, 2]
Q.18:

What will be the output of the following Python code?

>>>t1 = (1, 2, 4, 3)

>>>t2 = (1, 2, 3, 4)

>>>t1 < t2

A) True B) False
C) Error D) None
Q.19:

What will be the output of the following Python code?

>>>my_tuple = (1, 2, 3, 4)

>>>my_tuple.append( (5, 6, 7) )

>>>print len(my_tuple)

A) 1 B) 2
C) 5 D) Error
Q.20:

What will be the output of the following Python code ?

numberGames = {}

numberGames[(1,2,4)] = 8

numberGames[(4,2,1)] = 10

numberGames[(1,2)] = 12

sum = 0

for k in numberGames:

sum += numberGames[k]

print len(numberGames) + sum

A) 30 B) 24
C) 33 D) 12
Q.21:

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

A) { } B) set()
C) [ ]. D) ( )
Q.22:

What is the output of the following piece of code when executed in the python shell?

a={1,2,3} 

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

a

A) {2,3} B) Error, duplicate item present in list
C) Error, no method called intersection_update for set data type D) {1,4,5}
Q.23:

Which of the following lines of code will result in an error ?

A) s={abs} B) s={4, ‘abc’, (1,2)}
C) s={2, 2.2, 3, ‘xyz’} D) s={san}
Q.24:

What is the output of the code shown below ?

s=set([1, 2, 3])

s.union([4, 5])

s|([4, 5])

A) {1, 2, 3, 4, 5}{1, 2, 3, 4, 5} B) Error{1, 2, 3, 4, 5}
C) {1, 2, 3, 4, 5}Error D) ErrorError
Q.25:

What is the output of the line of code shown below,

if s1= {1, 2, 3}?

s1.issubset(s1)

A) True B) Error
C) No output D) False
Q.26:

Which of these about a frozenset is not true?

A) Mutable data type B) Allows duplicate values
C) Data type with unordered values D) Immutable data type
Q.27:

Is the following Python code valid?

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

>>> a

>>> a.add(5)

A) Yes, now a is {5,5,6,7} B) No, frozen set is immutable
C) No, invalid syntax for add method D) Yes, now a is {5,6,7}
Q.28:

What is the syntax of the following Python code ?

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

>>> a

A) {5,6,7} B) frozenset({5,6,7})
C) Error, not possible to convert set into frozenset D) Syntax error
Q.29:

Set members must not be hashable.

A) True B) False
Q.30:

What will be the output of the following Python code?

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

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

>>> a

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

What will be the output of the following Python code?

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

>>> b=a

>>> b.remove(3)

>>> a

A) {1,2,3} B) Error, copying of sets isn’t allowed
C) {1,2} D) Error, invalid syntax for remove
Q.32:

What will be the output of the following Python code?

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

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

>>> a

A) {2,3} B) Error, duplicate item present in list
C) Error, no method called intersection_update for set data type D) {1,4,5}
Q.33:

What will be the output of the following Python code?

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

>>> b=a.copy()

>>> b.add(4)

>>> a

A) {1,2,3} B) Error, invalid syntax for add
C) {1,2,3,4} D) Error, copying of sets isn’t allowed
Q.34:

What will be the output of the following Python code?

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

>>> b=a.add(4)

>>> b

A) 0 B) {1,2,3,4}
C) {1,2,3} D) Nothing is printed
Q.35:

What will be the output of the following Python code?

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

>>> b=frozenset([3,4,5])

>>> a-b

A) {1,2} B) Error as difference between a set and frozenset can’t be found out
C) Error as unsupported operand type for set data type D) frozenset({1,2})
Q.36:

What will be the output of the following Python code?

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

>>> {x*2 for x in a|{4,5}}

A) {2,4,6} B) Error, set comprehensions aren’t allowed
C) {8, 2, 10, 4, 6} D) {8,10}
Q.37:

What will be the output of the following Python code?

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

>>> sum(a,5)

A) 5 B) 23
C) 18 D) Invalid syntax for sum method, too many arguments
Q.38:

What will be the output of the following Python code?

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

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

>>> len(a+b)

A) 8 B) Error, unsupported operand ‘+’ for sets
C) 6 D) Nothing is displayed
Q.39:

What will be the output of the following Python code?

a={1,2,3}

b={1,2,3}

c=a.issubset(b)

print(c)

A) True B) Error, no method called issubset() exists
C) Syntax error for issubset() method D) False
Q.40:

Is the following Python code valid ?

a={1,2,3}

b={1,2,3,4}

c=a.issuperset(b)

print(c)

A) False B) True
C) Syntax error for issuperset() method D) Error, no method called issuperset() exists
Q.41:

Which line of code correctly initializes ‘grapes’ into the fruits dictionary?
fruits = {'apples': 1, 'bananas': 4, 'pears': 17, 'oranges': 14}

A) fruit['grapes'] B) fruit['grapes'] = 15
C) none D) insert 'grapes' in fruit
Answer & Explanation
Q.42:

What prints when the following code is run?
names = {'Janice': 5, 'Emily': 3, 'John': 7, 'Eleanor': 2}
list_o_names = []
for name in names:
if names[name] > 5:
list_o_names.append(name)
print(list_o_names

A) ['Janice', 'John'] B) ['Janice', 'Emily', 'Eleanor']
C) ['John'] D) none
Answer & Explanation
Q.43:

What does the following code print now that it has been updated?
names = {'Janice': 5, 'Emily': 3, 'John': 7, 'Eleanor': 2}
list_o_names = []
names['Emily'] += 10
names['Erik'] = 22
for name in names:
if names[name] > 5:
list_o_names.append(name)
print(list_o_names)

A) ['Emily', 'John', 'Erik'] B) ['Janice', 'Emily', 'John']
C) ['Janice', 'John', 'Erik'] D) cannot be determined
Answer & Explanation
Q.44:

What is the value of counter after the code is run to completion?
phrase = "Cheese in Philadelphia is extraordinary according to Erik"
counter = 0 letters = {} for word in phrase.split(): for letter in word: letter = letter.lower() if letter not in letters.keys(): letters[letter] = 0 letters[letter] += 1 for key in letters.keys(): if letters[key] > 2: counter += 1

A) 5 B) 10
C) 9 D) 8
Answer & Explanation
Q.45:

Which line of code correctly grabs the value of the key ‘apples’?
fruits = {'bananas': 7, 'apples': 4, 'grapes': 19, 'pears': 4}

A) fruits.get(apples) B) fruits.get('apples', 0)
C) fruits.get('apple') D) fruits.get(apples, 0)
Answer & Explanation
Q.46:

What value is printed once the code is run?

word = 'brontosaurus'
diction = {}
for letter in word:
if letter not in diction.keys():
diction[letter] = 0
diction[letter] += 1
print(diction.get('o', 0) + 4)

A) 10 B) 4
C) 8 D) 6
Answer & Explanation
Q.47:

What order do the keys print in after the following code is run? (Select all that apply)
counts = {'chuck' : 1, 'annie' : 42, 'jan' : 100}/
for key in counts:
print(key, counts[key])

A) jan, chuck, annie B) chuck, annie, jan
C) annie, chuck, jan D) All of these
Answer & Explanation
Q.48:

Which of the following is the correct way to initialize the string module?

A) import String B) import string
C) import string module D) none
Answer & Explanation
Q.49:

True or false? Python treats the words “Exciting” and “exciting” as the same word.

A)True B) False
Answer & Explanation
Q.50:

Which line of code correctly uses the .translate() method?

A) line.translate(str.maketrans(fromstr, tostr, deletestr)) B) line.translate(fromstr, tostr, deletestr)
C) line.translate(str.translate(fromstr, tostr, deletestr)) D) none
Answer & Explanation
Q.51:

NumPY stands for?

A) Numbering Python B) Number In Python
C) Numerical Python D) None Of the above
Answer & Explanation
Q.52:

NumPy is often used along with packages like?

A) Node.js B) Matplotlib
C) SciPy D) Both B and C
Answer & Explanation
Q.53:

The most important object defined in NumPy is an N-dimensional array type called?

A) ndarray B) narray
C) nd_array D) darray
Answer & Explanation
Q.54:

What will be output for the following code?
import numpy as np
a = np.array([1,2,3])
print a

A) [[1, 2, 3]] B) [1]
C) [1, 2, 3] D) Error
Answer & Explanation
Q.55:

What will be output for the following code?
import numpy as np
a = np.array([1, 2, 3], dtype = complex) print a

A) [[ 1.+0.j, 2.+0.j, 3.+0.j]] B) [ 1.+0.j]
C) Error D) [ 1.+0.j, 2.+0.j, 3.+0.j]
Answer & Explanation
Q.56:

Which of the following statement is false?

A) ndarray is also known as the axis array. B) ndarray.dataitemSize is the buffer containing the actual elements of the array.
C) NumPy main object is the homogeneous multidimensional array D) In Numpy, dimensions are called axes
Answer & Explanation
Q.57:

If a dimension is given as ____ in a reshaping operation, the other dimensions are automatically calculated.

A) Zero B) One
C) Negative one D) Infinite
Answer & Explanation
Q.58:

Which of the following sets the size of the buffer used in ufuncs?

A) bufsize(size) B) setsize(size)
C) setbufsize(size) D) size(size)
Answer & Explanation
Q.59:

What will be output for the following code?

import numpy as np
dt = dt = np.dtype('i4')
print dt

A) int32 B) int64
C) int128 D) int16
Answer & Explanation
Q.60:

Each built-in data type has a character code that uniquely identifies it.What is meaning of code "M"? r

A) timedelta B) datetime
C) objects D) Unicode
Answer & Explanation
Q.61:

The output of the code shown below is:

odd=lambda x: bool(x%2)
numbers=[n for n in range(10)]
print(numbers)
n=list()
for i in numbers:
  if odd(i):
  continue
else:
  break

A) [0, 2, 4, 6, 8, 10] B) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
C) [1, 3, 5, 7, 9] D) Error
Answer & Explanation
Q.62:

What is the output of the code shown below?

f=lambda x:bool(x%2)
print(f(20), f(21))

A) False True B) False False
C) True True D) True False
Answer & Explanation
Q.63:

What is the output of the code shown below?

import functools
l=[1,2,3,4]
print(functools.reduce(lambda x,y:x*y,l))

A) Error B) 10
C) 24 D) No output
Answer & Explanation
Q.64:

What is the output of the code shown?

l=[1, -2, -3, 4, 5]
def f1(x):
  return x<2
m1=filter(f1, l)
print(list(m1))

A) [1, 4, 5 ] B) Error
C) [-2, -3] D) [1, -2, -3]
Answer & Explanation
Q.65:

What is the output of the code shown below?

l=[-2, 4]
m=map(lambda x:x*2, l)
print(m)

A) [-4, 16] B) Address of m
C) Error D) -4
16
Answer & Explanation
Q.66:

What is the output of the following code?

l=[1, -2, -3, 4, 5]
def f1(x):
return x<-1 m1=map(f1, l)
print(list(m1))

A)[False, False, False, False, False] B) [False, True, True, False, False]
C) [True, False, False, True, True] D) [True, False, False, True, True]
Answer & Explanation
Q.67:

What is the output of the code shown?

l=[1, 2, 3, 4, 5]
m=map(lambda x:2**x, l)
print(list(m))

A) [1, 4, 9, 16, 25 ] B) [2, 4, 8, 16, 32 ]
C) [1, 0, 1, 0, 1] D) Error
Answer & Explanation
Q.68:

What is the output of the code shown?

import functools
l=[1, 2, 3, 4, 5]
m=functools.reduce(lambda x, y:x if x>y else y, l)
print(m)

A) Error B) Address of m
C) 1 D) 5
Answer & Explanation
Q.69:

What is the output of the code shown below?

l=[n for n in range(5)]
f=lambda x:bool(x%2)
print(f(3), f(1))
for i in range(len(l)):
  if f(l[i]):
  del l[i]
  print(i)

A) True True
1
2
Error
B) False False
1
2
C) True False
1
2
Error
D) False True
1
2
Answer & Explanation
Q.70:

What is the output of the code shown?

m=reduce(lambda x: x-3 in range(4, 10))
print(list(m))

A) [1, 2, 3, 4, 5, 6, 7] B) No output
C) [1, 2, 3, 4, 5, 6] D) Error
Answer & Explanation