Quiznetik

Python Programming | Set 1

1. What is the output of the following code : print 9//2

Correct : C. 4

2. Which function overloads the >> operator?

Correct : D. rshift()

3. What is the output of the following program : i = 0 while i < 3: print i print i+1

Correct : C. 0 1 1 2 2 3

4. Which module in Python supports regular expressions?

Correct : A. re

5. What is the output of the following program : print 0.1 + 0.2 == 0.3

Correct : B. False

6. Which of these is not a core data type?

Correct : D. Class

7. What data type is the object below? L = [1, 23, „hello‟, 1]

Correct : A. List

8. What is the output of the following program : def myfunc(a): a = a + 2 a = a * 2 return a print myfunc(2)

Correct : C. Indentation Error

9. What is the output of the expression : 3*1**3

Correct : C. 3

10. What is the output of the following program : print '{0:.2}'.format(1.0 / 3)

Correct : B. 0.33

11. What is the output of the following program : print '{0:-2%}'.format(1.0 / 3)

Correct : C. 33.33%

12. What is the output of the following program : i = 0 while i < 3: print i i += 1 else: print 0

Correct : B. 0 1 2 0

13. What is the output of the following program : i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0)

Correct : B. 0 1 2

14. What is the output of the following program : print 'cd'.partition('cd')

Correct : D. (”, „cd‟, ”)

15. What is the output of the following program : print 'abcefd'.replace('cd', '12')

Correct : B. abcefd

16. What will be displayed by the following code? def f(value, values): v = 1 values[0] = 44 t = 3 v = [1, 2, 3] f(t, v) print(t, v[0])

Correct : D. 3 44

17. Predict the output of following python programs dictionary1 = {'Google' : 1, 'Facebook' : 2, 'Microsoft' : 3 } dictionary2 = {'GFG' : 1, 'Microsoft' : 2, 'Youtube' : 3 } dictionary1.update(dictionary2); for key, values in dictionary1.items(): print(key, values)

Correct : C. („Google‟, 1) („Facebook‟, 2) („Youtube‟, 3) („Microsoft‟, 2) („GFG‟, 1)

18. What is the output of the following program? dictionary1 = {'GFG' : 1, 'Google' : 2, 'GFG' : 3 } print(dictionary1['GFG']);

Correct : C. 3

19. What is the output of the following program? temp = dict() temp['key1'] = {'key1' : 44, 'key2' : 566} temp['key2'] = [1, 2, 3, 4] for (key, values) in temp.items(): print(values, end = "")

Correct : B. {„key1‟: 44, „key2‟: 566}[1, 2, 3, 4]

20. What is the output of the following program? data = [2, 3, 9] temp = [[x for x in[data]] for x in range(3)] print (temp)

Correct : A. [[[2, 3, 9]], [[2, 3, 9]], [[2, 3, 9]]]

21. What is the output of the following program? data = [x for x in range(5)] temp = [x for x in range(7) if x in data and x%2==0] print(temp)

Correct : B. [0, 2, 4]

22. What is the output of the following program? L1 = [1, 2, 3, 4] L2 = L1 L3 = L1.copy() L4 = list(L1) L1[0] = [5] print(L1, L2, L3, L4)

Correct : D. [[5], 2, 3, 4] [[5], 2, 3, 4] [1, 2, 3, 4] [1, 2, 3, 4]

23. What is the output of the following program? import sys L1 = tuple() print(sys.getsizeof(L1), end = " ") L1 = (1, 2) print(sys.getsizeof(L1), end = " ") L1 = (1, 3, (4, 5)) print(sys.getsizeof(L1), end = " ") L1 = (1, 2, 3, 4, 5, [3, 4], 'p', '8', 9.777, (1, 3)) print(sys.getsizeof(L1))

Correct : C. 48 64 72 128

24. What is the output of the following program? T = (1, 2, 3, 4, 5, 6, 7, 8) print(T[T.index(5)], end = " ") print(T[T[T[6]-3]-6])

Correct : B. 5 8

25. What is the output of the following program? L = [1, 3, 5, 7, 9] print(L.pop(-3), end = ' ') print(L.remove(L[0]), end = ' ') print(L)

Correct : A. 5 None [3, 7, 9]

26. What is the output of the following program? def REVERSE(L): L.reverse() return(L) def YKNJS(L): List = list() List.extend(REVERSE(L)) print(List) L = [1, 3.1, 5.31, 7.531] YKNJS(L)

Correct : B. [7.531, 5.31, 3.1, 1]

27. What is the output of the following program? from math import sqrt L1 = [x**2 for x in range(10)].pop() L1 + = 19 print(sqrt(L1), end = " ") L1 = [x**2 for x in reversed(range(10))].pop() L1 + = 16 print(int(sqrt(L1)))

Correct : C. 10 .0 4

28. What is the output of the following program? D = dict() for x in enumerate(range(2)): D[x[0]] = x[1] D[x[1]+7] = x[0] print(D)

Correct : C. {0: 0, 7: 0, 1: 1, 8: 1}

29. What is the output of the following program? D = {1 : 1, 2 : '2', '1' : 1, '2' : 3} D['1'] = 2 print(D[D[D[str(D[1])]]])

Correct : B. 3

30. What is the output of the following program? D = dict() for i in range (3): for j in range(2): D[i] = j print(D)

Correct : B. {0: 1, 1: 1, 2: 1}

31. What is the output of the following program? from math import * a = 2.13 b = 3.7777 c = -3.12 print(int(a), floor(b), ceil(c), fabs(c))

Correct : B. 2 3 -3 3.12

32. What is the output of the following program?

Correct : D. [0, „2‟, „3‟, „5‟, „5‟, 0]

33. What is the output of the following program? import string import string Line1 = "And Then There Were None" Line2 = "Famous In Love" Line3 = "Famous Were The Kol And Klaus" Line4 = Line1 + Line2 + Line3 print(string.find(Line1, 'Were'), string.count((Line4), 'And'))

Correct : C. (15, 2)

34. What is the output of the following program? line = "What will have so will" L = line.split('a') for i in L: print(i, end=' ')

Correct : B. Wh t will h ve so will

35. What is the type of each element in sys.argv?

Correct : D. string

36. What is the length of sys.argv?

Correct : B. number of arguments + 1

37. What is the output of the following code? def foo(k): k[0] = 1 q = [0] foo(q) print(q)

Correct : B. [1].

38. What is the output of the following code? def foo(fname, val): print(fname(val)) foo(max, [1, 2, 3]) foo(min, [1, 2, 3])

Correct : A. 3 1

39. What is the output of the following? elements = [0, 1, 2] def incr(x): return x+1 print(list(map(elements, incr)))

Correct : C. error

40. What is the output of the following? elements = [0, 1, 2] def incr(x): return x+1 print(list(map(incr, elements)))

Correct : A. [1, 2, 3].

41. What is the output of the following? def to_upper(k): return k.upper() x = ['ab', 'cd'] print(list(map(to_upper, x)))

Correct : A. [„AB‟, „CD‟].

42. What is the output of the following? x = ['ab', 'cd'] print(len(list(map(list, x))))

Correct : A. 2

43. Program code making use of a given module is called a ______ of the module.

Correct : A. Client

44. What is the output of the following piece of code? #mod1 def change(a): b=[x*2 for x in a] print(b) #mod2 def change(a): b=[x*x for x in a] print(b) from mod1 import change from mod2 import change #main s=[1,2,3] change(s)

Correct : D. There is a name clash

45. What is the output of the following program? tday=datetime.date.today() print(tday.month())

Correct : D. 8

46. Which of the following formatting options can be used in order to add „n‟ blank spaces after a given string „S‟?

Correct : D. print(“%-ns”%S)

47. What is the output of the following program? f = None for i in range (5): with open("data.txt", "w") as f: if i > 2: break print(f.closed)

Correct : A. True

48. To read the entire remaining contents of the file as a string from a file object infile, we use

Correct : B. infile.read()

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

Correct : B. t[3] = 45