Python Programming Set 2
Computer Science Engineering (CSE),
Information Technology Engineering (IT),
Bachelor of Science in Information Technology FY (BSc IT),
Bachelor of Science in Information Technology SY (BSc IT),
Bachelor of Science in Information Technology TY (BSc IT),
Master of Science in Information Technology (MSc IT),
Master of Science in Computer Science (MSc CS),
On This Page
This set of Python Programming Multiple Choice Questions & Answers (MCQs) focuses on Python Programming Set 2
Q1 | 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)
- 5 None [3, 7, 9]
- 5 1 [3, 7, 9]
- 5 1 [3, 7, 9]
- 5 None [1, 3, 7, 9]
Q2 | 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)
- [1, 3.1, 5.31, 7.531]
- [7.531, 5.31, 3.1, 1]
- IndexError
- AttributeError: „NoneType? object has no attribute „REVERSE?
Q3 | What is the output of the following program?from math import sqrtL1 = [x**2 for x in range(10)].pop()L1 + = 19print(sqrt(L1), end = " ")L1 = [x**2 for x in reversed(range(10))].pop()L1 + = 16print(int(sqrt(L1)))
- 10.0 4.0
- 4.3588 4
- 10 .0 4
- 10.0 0
Q4 | 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)
- KeyError
- {0: 1, 7: 0, 1: 1, 8: 0}
- {0: 0, 7: 0, 1: 1, 8: 1}
- {1: 1, 7: 2, 0: 1, 8: 1}
Q5 | What is the output of the following program?D = {1 : 1, 2 : '2', '1' : 1, '2' : 3}D['1'] = 2print(D[D[D[str(D[1])]]])
- 2
- 3
- „2?
- KeyError
Q6 | What is the output of the following program?D = dict()for i in range (3):for j in range(2):D[i] = jprint(D)
- {0: 0, 1: 0, 2: 0}
- {0: 1, 1: 1, 2: 1}
- {0: 0, 1: 0, 2: 0, 0: 1, 1: 1, 2: 1}
- TypeError: Immutable object
Q7 | What is the output of the following program? from math import *a = 2.13b = 3.7777c = -3.12print(int(a), floor(b), ceil(c), fabs(c))
- 2 3 -4 3
- 2 3 -3 3.12
- 2 4 -3 3
- 2 3 -4 3.12
Q8 | What is the output of the following program?
- [0, „2?, „3?, „4?, „5?, 0]
- [„6?, „2?, „3?, „5?, „5?, „6?]
- [„0?, „2?, „3?, „5?, „5?, „0?]
- [0, „2?, „3?, „5?, „5?, 0]
Q9 | What is the output of the following program?import stringimport stringLine1 = "And Then There Were None"Line2 = "Famous In Love"Line3 = "Famous Were The Kol And Klaus"Line4 = Line1 + Line2 + Line3print(string.find(Line1, 'Were'), string.count((Line4), 'And'))
- True 1
- 15 2
- (15, 2)
- True 2
Q10 | 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=' ')
- [„What?, „will?, „have?, „so?, „will?]
- Wh t will h ve so will
- What will have so will
- [„Wh?, „t will h?, „ve so will?]
Q11 | What is the type of each element in sys.argv?
- set
- list
- tuple
- string
Q12 | What is the length of sys.argv?
- number of arguments
- number of arguments + 1
- number of arguments – 1
- none of the mentioned
Q13 | What is the output of the following code?def foo(k):k[0] = 1q = [0]foo(q)print(q)
- [0].
- [1].
- [1, 0].
- [0, 1].
Q14 | 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])
- 3 1
- 1 3
- error
- none of the mentioned
Q15 | What is the output of the following?elements = [0, 1, 2]def incr(x):return x+1print(list(map(elements, incr)))
- [1, 2, 3].
- [0, 1, 2].
- error
- none of the mentioned
Q16 | What is the output of the following?elements = [0, 1, 2]def incr(x):return x+1print(list(map(incr, elements)))
- [1, 2, 3].
- [0, 1, 2].
- error
- none of the mentioned
Q17 | What is the output of the following?def to_upper(k):return k.upper()x = ['ab', 'cd']print(list(map(to_upper, x)))
- [„AB?, „CD?].
- [„ab?, „cd?].
- none of the mentioned
- error
Q18 | What is the output of the following?x = ['ab', 'cd']print(len(list(map(list, x))))
- 2
- 4
- error
- none of the mentioned
Q19 | Program code making use of a given module is called a ______ of the module.
- Client
- Docstring
- Interface
- Modularity
Q20 | What is the output of the following piece of code?#mod1def change(a):b=[x*2 for x in a]print(b)#mod2def change(a):b=[x*x for x in a]print(b)from mod1 import changefrom mod2 import change#mains=[1,2,3]change(s)
- [2,4,6].
- [1,4,9].
- [2,4,6].
- There is a name clash
Q21 | What is the output of the following program? tday=datetime.date.today()print(tday.month())
- August
- Aug
- 8
- 8
Q22 | Which of the following formatting options can be used in order to add „n? blank spacesafter a given string „S??
- print(“-ns”%S)
- print(“-ns”%S)
- print(“%ns”%S)
- print(“%-ns”%S)
Q23 | What is the output of the following program?f = Nonefor i in range (5):with open("data.txt", "w") as f:if i > 2:breakprint(f.closed)
- TRUE
- FALSE
- None
- Error
Q24 | To read the entire remaining contents of the file as a string from a file object infile, we use
- infile.read(2)
- infile.read()
- infile.readline()
- infile.readlines()
Q25 | Suppose t = (1, 2, 4, 3), which of the following is incorrect?
- print(t[3])
- t[3] = 45
- print(max(t))
- print(len(t))