Which of the following would give an error?
A) list1=[] | B) list1=[]*3 |
C) list1=[2,8,7] | D) None of the above |
Which of the following would give an error?
A) list1=[] | B) list1=[]*3 |
C) list1=[2,8,7] | D) None of the above |
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. |
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] |
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]) |
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)) |
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 |
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 |
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] |
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 |
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 |
Which of the following is a Python tuple ?
A) [1, 2, 3] | B) (1, 2, 3) |
C) {1, 2, 3} | D) {} |
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)) |
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) |
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) |
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) |
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” |
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] |
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 |
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 |
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 |
Which of the following statements is used to create an empty set?
A) { } | B) set() |
C) [ ]. | D) ( ) |
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} |
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} |
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 |
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 |
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 |
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} |
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 |
Set members must not be hashable.
A) True | B) False |
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 |
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 |
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} |
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 |
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 |
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}) |
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} |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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) |
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 |
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 |
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 |
True or false? Python treats the words “Exciting” and “exciting” as the same word.
A)True | B) False |
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 |
NumPY stands for?
A) Numbering Python | B) Number In Python |
C) Numerical Python | D) None Of the above |
NumPy is often used along with packages like?
A) Node.js | B) Matplotlib |
C) SciPy | D) Both B and C |
The most important object defined in NumPy is an N-dimensional array type called?
A) ndarray | B) narray |
C) nd_array | D) darray |
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 |
What will be output for the following code?
import numpy as np
a = np.array([1, 2, 3], dtype = complex)
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] |
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 |
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 |
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) |
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 |
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 |
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 |
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 |
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 |
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] |
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 |
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] |
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 |
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 |
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 |
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 |
Which of the following would give an error?
A) list1=[] | B) list1=[]*3 |
C) list1=[2,8,7] | D) None of the above |
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. |
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] |
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]) |
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)) |
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 |
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 |
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] |
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 |
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 |
Which of the following is a Python tuple ?
A) [1, 2, 3] | B) (1, 2, 3) |
C) {1, 2, 3} | D) {} |
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)) |
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) |
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) |
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) |
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” |
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] |
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 |
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 |
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 |
Which of the following statements is used to create an empty set?
A) { } | B) set() |
C) [ ]. | D) ( ) |
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} |
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} |
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 |
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 |
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 |
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} |
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 |
Set members must not be hashable.
A) True | B) False |
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 |
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 |
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} |
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 |
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 |
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}) |
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} |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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) |
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 |
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 |
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 |
True or false? Python treats the words “Exciting” and “exciting” as the same word.
A)True | B) False |
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 |
NumPY stands for?
A) Numbering Python | B) Number In Python |
C) Numerical Python | D) None Of the above |
NumPy is often used along with packages like?
A) Node.js | B) Matplotlib |
C) SciPy | D) Both B and C |
The most important object defined in NumPy is an N-dimensional array type called?
A) ndarray | B) narray |
C) nd_array | D) darray |
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 |
What will be output for the following code?
import numpy as np
a = np.array([1, 2, 3], dtype = complex)
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] |
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 |
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 |
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) |
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 |
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 |
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 |
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 |
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 |
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] |
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 |
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] |
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 |
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 |
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 |
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 |
Which of the following would give an error?
A) list1=[] | B) list1=[]*3 |
C) list1=[2,8,7] | D) None of the above |
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. |
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] |
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]) |
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)) |
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 |
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 |
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] |
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 |
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 |
Which of the following is a Python tuple ?
A) [1, 2, 3] | B) (1, 2, 3) |
C) {1, 2, 3} | D) {} |
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)) |
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) |
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) |
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) |
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” |
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] |
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 |
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 |
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 |
Which of the following statements is used to create an empty set?
A) { } | B) set() |
C) [ ]. | D) ( ) |
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} |
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} |
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 |
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 |
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 |
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} |
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 |
Set members must not be hashable.
A) True | B) False |
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 |
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 |
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} |
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 |
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 |
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}) |
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} |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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) |
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 |
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 |
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 |
True or false? Python treats the words “Exciting” and “exciting” as the same word.
A)True | B) False |
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 |
NumPY stands for?
A) Numbering Python | B) Number In Python |
C) Numerical Python | D) None Of the above |
NumPy is often used along with packages like?
A) Node.js | B) Matplotlib |
C) SciPy | D) Both B and C |
The most important object defined in NumPy is an N-dimensional array type called?
A) ndarray | B) narray |
C) nd_array | D) darray |
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 |
What will be output for the following code?
import numpy as np
a = np.array([1, 2, 3], dtype = complex)
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] |
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 |
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 |
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) |
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 |
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 |
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 |
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 |
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 |
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] |
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 |
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] |
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 |
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 |
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 |
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 |
Not a member yet? Register now
Are you a member? Login now