0% found this document useful (0 votes)
49 views49 pages

QB - Python Basics - Ver 7.0

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views49 pages

QB - Python Basics - Ver 7.0

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON BASICS

QUESTION BANK

Admin Office House of G-TEC, Calicut-02., India. | Corp. Office Peace Centre, Singapore – 228149
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

1. Select the reserved keyword in python


a) else b) import
c) raise d) All of these
2. Which of the following symbols are used for comments in Python?
a) // b) ''
c) /**/ d) #
3. Are nested if-else are allowed in Python?
a) Yes b) No
4. Which keyword is used to define methods in Python?
a) function b) def c) method
5. Which of the following is correct way to declare string variable in Python?
a) fruit = 'banana' b) fruit = "banana" c) Both
6. Which predefined Python function is used to find length of string?
a) length() b) len() c) strlen()
7. Python allows string slicing. What is the output of below code:?
str='G-TEC Singapore'
print(str[3:5])
a) TEC b) TE c) EC
8. Syntax of constructor in Python?
a) def __init__() b) def _init_() c) _init_()
9. How to find the last element of list in Python? Assume `bikes` is the name of list.
a) bikes[0] b) bikes[-1] c) bikes[lpos]
10. What is correct syntax to copy one list into another?
a) listA = listB[] b) listA = listB[:] c) listA = listB[]()
11. If a='GTEC', b='EDUCATION' then which of the following operation would show
'GTECEDUCATION' as output?
a) a+b b) a+""+b c) All of the above
12. If a='gtec', b='education' then what is the output of:
c = a-b
printc)
a) gtec-education
b) gteceducation
c) TypeError: unsupported operand
13. What is the output of the following?
a = 8.6
b=2
print a//b
a) 4.3 b) 4.0 c) 4
14. Find the output of the following
a = True
b = False
c = True
if not a or b:

Page 1 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

print "a"
elif not a or not b and c:
print "b"
elif not a or b or not b and a:
print "c"
else:
print "d"
a) a b) b c) c
15. Find the output of the following
class test:
def __init__(self):
print "Hello World"
def __init__(self):
print "Bye World"
obj=test()
a) Hello World b) Compilation Error c) Bye World
16. The format function, when applied on a string returns:
a) list b) bool
c) int d) str
17. print(chr(ord('b')+1))
a) b b) syntax error c) c
18. Which statement is correct...?
a) List is mutable && Tuple is immutable
b) List is immutable && Tuple is mutable
c) Both are Immutable
d) Both are Mutable
19. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
a) Error b) 25
c) None d) 2
20. To open a file c:[Link] for writing, we use
a) outfile = open(file = “c:[Link]”, “o”)
b) outfile = open(“c:[Link]”, “r”)
c) outfile = open(“c:[Link]”, “w”)
d) outfile = open(“c:[Link]”, “r”)
21. What is answer of this expression, 22 % 3 is?
a) 7 b) 1
c) 0 d) 5
22. Which of the following will run without errors?
a) round(45.8) b) round(6352.898,2,5)
c) round() d) round(7463.123,2,1)
23. All keywords in Python are in
a) lower case b) UPPER CASE
c) Capitalized d) None of the mentioned

Page 2 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

24. Which of these in not a core datatype?


a) Lists b) Dictionary
c) Tuples d) Class
25. Which of the following represents the bitwise XOR operator?
a) & b) ^
c) | d)!
26. What is the output of the following?
i=1
while True:
if i%0O7 == 0:
break
print(i)
i += 2
a) 1 2 3 4 5 6 b) 1 2 3 4 5 6 7
c) error d) 1 3 5
27. What is the output of the following?
True = False
while True:
print(True)
break
a) True b) False
c) None d) none of the mentioned
28. max("what are you")
a) error b) u
c) t d) y
29. What is the output when following code is executed?
str1 = 'hello'
str2 = ','
str3 = 'world'
str1[-1:]
a) olleh b) hello
c) h d) o
30. What arithmetic operators cannot be used with strings?
a) + b) *
c) – d) All of these
31. What is the output of the following code?
nums = set([1,1,2,3,3,3,4,4])
print(len(nums))
a) 7 b) 4
c) 8 d) Error, invalid syntax for of set
32. Select all options that print hello-how-are-you
a) print('hello', 'how', 'are', 'you')
b) print('hello', 'how', 'are', 'you' + '-' * 4)
c) print('hello' + '-' + 'how' + '-' + 'are' + '-' + 'you')
Page 3 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

33. What is the return value of trunc()?


a) Int b) bool
c) float d) None
34. Which of these in not a core datatype
a) Lists b) Dictionary
c) Tuples d) Class
35. Given a function that does not return any value, what value is thrown by itby default when
executed in shell
a) int b) bool
c) void d) None
36. Following set of commands are executed in shell, what will be the output?
str="hello"
str[:2]
str
a) he b) lo
c) olleh d) hello
37. Which of the following will run without errors(multiple answers possible)?
a) round(45.8) b) round()
c) round(6352.89 d) round(7463.123,2,1)
38. What is the return type of function id?
a) int b) float
c) bool d) dict
39. What error occurs when you execute? apple = mango
a) SyntaxError b) NameError
c) ValueError d) TypeError
40. Carefully observe the code and give the answer.
def examplea):
a = a + '2'
a = a*2
return a
example("hello")
a) indentation Error
b) hello2
c)hello2hello2
d) cannot perform mathematical operation on strings
41. What dataype is the object below ? L = [1, 23, 'hello',1]
a) List b) dictionary
c) array d) tuple
42. Which of the following results in a SyntaxError(Multiple answers possible)?
a) '"?Once upon a time..."?, she said.'
b) "He said, "Yes!"?"?
c) '3f
d) "?'That's okay"?'

Page 4 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

43. What is the average value of the code that is executed below?
grade1 = 80
grade2 = 90
average = (grade1 + grade2) / 2
a) 85 b) 85.0
c) 95 d) 95.0
44. Which of the following is the use of function in python?
a) Functions are reusable pieces of programs
b) Functions don't provide better modularity for your application
c) you can't also create your own functions
45. Which keyword is use for function?
a) Fun b) Define
b) c) Def d) Function
46. What is the output of the below program?
def sayHello():
print('Hello World!')
sayHello()
sayHello
a) Hello World! Hello World! c) Hello Hello
b) 'Hello World!' 'Hello World!' d) None of the mentioned
47. What is the output of the below program?
def printMax(a, b):
if a > b:
print(a, 'is maximum')
elseif a == b:
print(a, 'is equal to', b)
else:
print(b, 'is maximum')
printMax(3, 4)
a) 3 b) 4 c) 4 is maximum
48. What is the output of the below program?
x = 50
?
def func():
global x
?
print('x is', x)
x=2
print('Changed global x to', x)
func()
print('Value of x is', x)

Page 5 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

a) x is 50 Changed global x to 2 Value of x is 50


b) x is 50 Changed global x to 2 Value of x is 2
c) x is 50 Changed global x to 50 Value of x is 50
49. What is the output of below program?
def say(message, times = 1):
print(message * times)
?
say('Hello')
say('World', 5)
a) Hello WorldWorldWorldWorldWorld
b) Hello World 5
c) Hello World,World,World,World,World
d) Hello d
50. What is the output of the below program?
def func(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and c is', c)
?
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)
a) a is 7 and b is 3 and c is 10 a is 25 and b is 5 and c is 24 a is 5 and b is 100 and c is 50
b) a is 3 and b is 7 and c is 10 a is 5 and b is 25 and c is 24 a is 50 and b is 100 and c is 5
c) a is 3 and b is 7 and c is 10 a is 25 and b is 5 and c is 24 a is 100 and b is 5 and c is 50
51. Which of the following is a features of DocString?
a) Provide a convenient way of associating documentation with Python modules, functions,
classes, and methods
b) All functions should have a docstring
c) All of the mentioned
52. What is called when a function is defined inside a class?
a) Module c) Another function
b) Class d) Method
53. Which of the following is the use of id() function in python?
a) Id returns the identity of the object
b) Every object doesn't have a unique id
c) None of the mentioned
54. Which of the following refers to mathematical function?
a) sqrt c) add
b) rhombus d) rhombus
55. What is the output of the below program?
def C2Fc):
return c * 9/5 + 32
print C2F(100)
print C2F(0)
Page 6 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

a) 212 32 c) 567 98
b) 314 24 d) None of the mentioned
56. What is the output of this program?
y=6
?
z = lambda x: x * y
print z (8)
a) 48 c) 64
b) 14 d) None of the mentioned
57. What is the output of below program?
lamb = lambda x: x ** 3
print(lamb(5))
a) 15 c) 125
b) 555 d) None of the mentioned
58. s Lambda contains return statements?
a) True b) False
59. What is the output of below program?
def writer():
title = 'Sir'
name = (lambda x:title + ' ' + x)
return name
?
who = writer()
who('Arthur')
a) Arthur Sir c) Arthur
b) Sir Arthur d) None of the mentioned
60. What is the output of this program?
min = (lambda x, y: x if x < y else y)
min(101*99, 102*98)
a) 9997 b) 9999 c) 9996
61. How many except statements can a try-except block have?
a) zero c) more than one
b) one d) more than zero
62. When will the else part of try-except-else be executed?
a) when an exception occurs
b) when no exception occurs
c) when an exception occurs in to except block
63. Is the following code valid?
try:
# Do something
except:
# Do something
finally:
# Do something

Page 7 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

a) no, there is no such thing as finally


b) no, finally cannot be used with except
c) no, finally must come before except
d) yes
64. Can one block of except statements handle multiple exception?
a) yes, like except TypeError, SyntaxError [,...]
b) yes, like except [TypeError, SyntaxError]
c) no
65. When is the finally block executed?
a) when there is no exception
b) when there is an exception
c) only if some condition that has been specified is satisfied
d) always
66. What is the output of the following code?
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
a) 1
b) 2
c) 3
d) error, there is more than one return statement in a single try-finally block
67. What is the type of each element in [Link]?
a) set c) tuple
b) list d) string
68. What is the output of the following code?
def foo(k):
k[0] = 1
q = [0]
foo(q)
print(q)
a) [0] c) [1, 0]
b) [1] d) [0, 1]
69. What is the length of [Link]?
a) number of arguments
b) number of arguments + 1
c) number of arguments? 1
70. How many keyword arguments can be passed to a function in a single function call?
a) zero c) zero or more
b) one d) one or more
Page 8 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

71. 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])
a) 3 1 c) error
b) 1 3 d) none of the mentioned
72. What is the output of the following code?
def foo():
return total + 1
total = 0
print(foo())
a) 0 c) error
b) 1 d) none of the mentioned
73. What is the output of the following code?
def foo():
total += 1
return total
total = 0
print(foo())
a) 0 b) 1 c) Error
74. What is the output of the following code?
def foo(x):
x = ['def', 'abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
a) True c) None
b) False d) Error
75. What is the output of the following code?
def foo(i, x=[]):
[Link](i)
return x
for i in range(3):
print(foo(i))
a) [0] [1] [2] c) [1] [2] [3]
b) [0] [0, 1] [0, 1, 2] d) [1] [1, 2] [1, 2, 3]
76. What is the output of the following code?
def foo(k):
k = [1]
q = [0]
foo(q)
print(q)
a) [0] c) [1, 0]
b) [1] d) [0, 1]

Page 9 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

77. How are variable length arguments specified in the function heading?
a) one star followed by a valid identifier
b) one underscore followed by a valid identifier
c) two stars followed by a valid identifier
d) two underscores followed by a valid identifier
78. Which module in the python standard library parses options received from the command
line?
a) getopt c) getarg
b) os d) main
79. What is the type of [Link]?
a) set c) tuple
b) list d) string
80. What is the value stored in [Link][0]?
a) null c) the program's name
b) you cannot access it d) the first argument
81. How are default arguments specified in the function heading?
a) identifier followed by an equal to sign and the default value
b) identifier followed by the default value within backticks (")
c) identifier
82. What is the output of the following code?
def foo(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
a) True c) None
b) False d) Error
83. What is the output of the following?
def foo(i, x=[]):
[Link]([Link](i))
return x
for i in range(3):
y = foo(i)
print(y)
a) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]
b) [[0], [[0], 1], [[0], [[0], 1], 2]]
c) [[0], None, [1], None, [2], None]
d) [[[0]], [[[0]], [1]], [[[0]], [[[0]], [1]], [2]]]
84. What is the output of the following?
k = [print(i) for i in my_string if i not in "aeiou"]
a) prints all the vowels in my_string
b) prints all the consonants in my_string
c) prints all characters of my_string that aren't vowels

Page 10 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

85. What is the output of print(k) in the following?


k = [print(i) for i in my_string if i not in "aeiou"]
print(k)
a) all characters of my_string that aren't vowels
b) a list of Nones
c) list of Trues
d) list of Falses
86. What is the output of the following?
my_string = "hello world"
k = [([Link](), len(i)) for i in my_string]
print(k)
a) [('HELLO', 5), ('WORLD', 5)]
b) [('H', 1), ('E', 1), ('L', 1), ('L', 1), ('O', 1), (' ', 1), ('W', 1), ('O', 1), ('R', 1), ('L', 1), ('D', 1)]
c) [('HELLO WORLD', 11)]
d) none of the mentioned
87. What is the output of the following?
x = [i**+1 for i in range(3)]; print(x);
a) [0, 1, 2] c) error, **+ is not a valid operator
b) [1, 2, 5] d) error, ';' is not allowed
88. What is the output of the following?
print([[Link]() for i in "HELLO"])
a) ['h', 'e', 'l', 'l', 'o'] c) ['hello']
b) 'hello' d) Hello
89. What is the output of the following?
print([[i+j for i in "abc"] for j in "def"])
a) ['da', 'ea', 'fa', 'db', 'eb', 'fb', 'dc', 'ec', 'fc']
b) [['ad', 'bd', 'cd'], ['ae', 'be', 'ce'], ['af', 'bf', 'cf']]
c) [['da', 'db', 'dc'], ['ea', 'eb', 'ec'], ['fa', 'fb', 'fc']]
d) ['ad', 'ae', 'af', 'bd', 'be', 'bf', 'cd', 'ce', 'cf']
90. What is the output of the following?
print([if i%2==0: i; else: i+1; for i in range(4)])
a) [0, 2, 2, 4] b) [1, 1, 3, 3] c) error
91. What is the output of the following?
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(incr, elements)))
a) [1, 2, 3] b) [0, 1, 2] c) Error
92. What is the output of the following?
x = ['ab', 'cd']
print(list(map(upper, x)))
a) ['AB', 'CD']
b) ['ab', 'cd']
c) Error

Page 11 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

93. What is the output of the following?


def to_upper(k):
return [Link]()
x = ['ab', 'cd']
print(list(map(to_upper, x)))
a) ['AB', 'CD']
b) ['ab', 'cd']
c) none of the mentioned
94. What is the output of the following?
def to_upper(k):
[Link]()
x = ['ab', 'cd']
print(list(map(to_upper, x)))
a) ['AB', 'CD'] b) ['ab', 'cd'] c) none of these
95. What is the output of the following?
x = ['ab', 'cd']
print(map(len, x))
a) ['ab', 'cd'] c) ['2', '2']
b) [2, 2] d) none of the mentioned
96. What is the output of the following?
x = ['ab', 'cd']
print(list(map(len, x)))
a) ['ab', 'cd'] c) ['2', '2']
b) [2, 2] d) none of the mentioned
97. What is the output of the following?
x = ['ab', 'cd']
print(len(list(map(list, x))))
a) 2 c) error
b) 4 d) none of the mentioned
98. What is the output of the following?
x = [12, 34]
print(len(list(map(len, x))))
a) 2 b) 1 c) Error
99. What is of the following?
x = [12, 34]
print(len(''.join(list(map(str, x)))))
a) 4 b) 5 c) 6
100. What is the output of the following?
x = [12.1, 34.0]
print(' '.join(list(map(str, x))))
a) 12 1 34 0 c) 121 340
b) 12.1 34 d) 12.1 34.0

Page 12 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

101. What is the output of the following?


x = [[0], [1]]
print(len(' '.join(list(map(str, x)))))
a) 2 b) 3 c) 7
102. What is the output of the following?
x = [[0], [1]]
print((' '.join(list(map(str, x)))))
a) ('[0] [1]',) b) ('01',) c) [0] [1]
103. Which function is called when the following code is executed?
f = foo()
format(f)
a) format() c) str()
b) __format__() d) __str__()
104. What is returned by [Link](3.4)?
a) 3 b) 4 c) 4.0
105. What is the output of print([Link](3, -1))?
a) 1.0 b) -3 c) -3.0
106. Is the function abs() same as [Link]()?
a) sometimes c) never
b) always d) none of the mentioned
107. What is the value returned by [Link](6)?
a) 720 c) [1, 2, 3, 6]
b) 6 d) Error
108. What is the value of x if x = [Link](0)?
a) 0 c) error
b) 1 d) none of the mentioned
109. What is [Link](4.0)?
a) 24 c) error
b) 1 d) none of the mentioned
110. What is the output of print ([Link](4.5))?
a) 24 c) error
b) 120 d) none of the mentioned
111. What is [Link](0o10)?
a) 8 c) 0
b) 10 d) 9
112. What does the function [Link](x) return?
a) a tuple containing of the mantissa and the exponent of x
b) a list containing of the mantissa and the exponent of x
c) a tuple containing of the mantissa of x
d) a list containing of the exponent of x
113. What is the result of [Link]([.1 for i in range(20)])?
a) 2.0 c) 2
b) 20 d) 2.0000000000000004

Page 13 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

114. What is the result of sum([.1 for i in range(20)])?


a) 2.0 c) 2
b) 20 d) 2.0000000000000004
115. What is returned by [Link](float('inf'))?
a) True c) None
b) False d) Error
116. What is returned by [Link](float('nan'))?
a) True c) None
b) False d) Error
117. What is x if x = [Link](float('0.0'))?
a) True c) None
b) False d) Error
118. What is the result of the following?
-float('inf') + float('inf')
a) inf c) 0
b) nan d) 0.0
119. What is the output of the following?
print([Link](float('-inf')))
a) error, the minus sign shouldn't havve been inside the brackets
b) error, there is no function called isinf
c) 1
d) 0
120. What is the value of x if x = [Link](0.5, 1)?
a) 1 c) 0.5
b) 2.0 d) none of the mentioned
121. What is returned by [Link](1.0)?
a) (0.0, 1.0) c) (0.5, 1)
b) (1.0, 0.0) d) (0.5, 1.0)
122. What is the result of [Link](3.1)?
a) 3.0 b) 3 c) 0.1
123. What is the output of print([Link]('3.1'))?
a) 3 c) error
b) 3.0 d) none of the mentioned
124. Which of the following is the same as [Link](p)?
a) e ** p c) p ** e
b) math.e ** p d) p ** math.e
125. What is returned by math.expm1(p)?
a) (math.e ** p) ? 1 c) error
b) math.e ** (p ? 1) d) none of the mentioned
126. What is the default base used when [Link](x) is found?
a) e c) 2
b) 10 d) none of the mentioned

Page 14 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

127. Which of the following aren't defined in the math module?


a) log2() c) logx()
b) log10() d) none of the mentioned
128. What is returned by int([Link](3, 2))?
a) 6 c) error, third argument required
b) 9 d) error, too many arguments
129. What is output of print([Link](3, 2))?
a) 9 c) None
b) 9.0 d) none of the mentioned
130. What is the value of x if x = [Link](4)?
a) 2 c) (2, -2)
b) 2.0 d) (2.0, -2.0)
131. What does [Link](X, Y) do?
a) calculate the Xth root of Y
b) calculate the Yth root of X
c) error
132. What the does [Link](3) return?
a) True c) 3
b) None d) 1
133. Which of the following cannot be returned by [Link](4)?
a) 0 c) 2.3
b) 3 d) none of the mentioned
134. Which of the following is equivalent to [Link](3)?
a) range(3) c) [Link](range(3))
b) [Link](range(0, 3)) d) [Link](range(3))
135. The function [Link](4) can return only which one of the following values?
a) 4 c) error
b) 3.4 d) none of the mentioned
136. Which of the following is equivalent to [Link](3, 6)?
a) [Link]([3, 6]) c) 3 + [Link](3)
b) [Link](3, 6) d) 3 + [Link](4)
137. Which of the following will not be returned by [Link]("1 ,"?)?
a) 1 c) ,
b) (space) d) none of the mentioned
138. Which of the following will never be displayed on executing print([Link]({0: 1, 2:
3}))?
a) 0 c) KeyError: 1
b) 1 d) none of the mentioned
139. Which type of elements are accepted by [Link]()?
a) strings c) tuples
b) lists d) integers

Page 15 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

140. What is the range of values that [Link]() can return?


a) [0.0, 1.0] c) (0.0, 1.0)
b) (0.0, 1.0] d) [0.0, 1.0)
141. To open a file c:\[Link] for reading, we use?
a) infile = open("c:\[Link]"?, "r"?)
b) infile = open("c:\\[Link]"?, "r"?)
c) infile = open(file = "c:\[Link]"?, "r"?)
d) infile = open(file = "c:\\[Link]"?, "r"?)
142. To open a file c:\[Link] for writing, we use?
a) outfile = open("c:\[Link]"?, "w"?)
b) outfile = open("c:\\[Link]"?, "w"?)
c) outfile = open(file = "c:\[Link]"?, "w"?)
d) outfile = open(file = "c:\\[Link]"?, "w"?)
143. To open a file c:\[Link] for appending data, we use?
a) outfile = open("c:\\[Link]"?, "a"?)
b) outfile = open("c:\\[Link]"?, "rw"?)
c) outfile = open(file = "c:\[Link]"?, "w"?)
d) outfile = open(file = "c:\\[Link]"?, "w"?)
144. To read two characters from a file object infile, we use?
a) [Link](2)
b) [Link]()
c) [Link]()
d) [Link]()
145. To read the entire remaining contents of the file as a string from a file object infile, we use
a) [Link](2)
b) [Link]()
c) [Link]()
d) [Link]()
146. What is the output?
f = None
?
for i in range (5):
with open("[Link]", "w") as f:
if i > 2:
break
?
print [Link]
a) True c) None
b) False d) Erro
147. To read the next line of the file from a file object infile, we use?
a) [Link](2) c) [Link]()
b) [Link]() d) [Link]()

Page 16 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

148. To read the remaining lines of the file from a file object infile, we use?
a) [Link](2) c) [Link]()
b) [Link]() d) [Link]()
149. The readlines() method returns
a) str c) a list of single characters
b) a list of lines d) a list of integers
150. What is the output of this program?
str = raw_input("Enter your input: ");
print "Received input is : ", str
a) Enter your input: Hello Python Received input is : Hello Python
b) Enter your input: Hello Python Received input is : Hello
c) Enter your input: Hello Python Received input is : Python
d) None of the mentioned
151. What is the output of this program?
str = input("Enter your input: ");
print "Received input is : ", str
a) Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 20, 30, 40]
b) Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 30, 20, 40]
c) Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 10, 30, 40]
d) None of the mentioned
152. Which one of the following is not attributes of file?
a) closed c) rename
b) softspace d) mode
153. What is the output of this program?
import sys
print 'Enter your name: ',
?
name = ''
?
while True:
c = [Link](1)
if c == '\n':
break
name = name + c
?
print 'Your name is:', name
If entered name is sanfound
a) sanfoundry c) San
b) sanfoundry, sanfoundry d) None of the mentioned
154. Which of the following is a Python tuple?
a) [1, 2, 3] c) {1, 2, 3}
b) (1, 2, 3) d) {}

Page 17 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

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


a) print(t[3]) c) print(max(t))
b) t[3] = 45 d) print(len(t))
156. What will be the output?
t=(1,2,4,3)
t[1:3]
a) (1, 2) c) (2, 4)
b) (1, 2, 4) d) (2, 4, 3)
157. What will be the output?
t=(1,2,4,3)
t[1:-1]
a) (1, 2) c) (2, 4)
b) (1, 2, 4) d) (2, 4, 3)
158. What will be the output?
d = {"john":40, "peter":45}
d["john"]
a) 40 c) "john"?
b) 45 d) "peter"?
159. What will be the output?
t = (1, 2)
2*t
a) (1, 2, 1, 2) c) (1, 1, 2, 2)
b) [1, 2, 1, 2] d) [1, 1, 2, 2]
160. What will be the output?
my_tuple = (1, 2, 3, 4)
my_tuple.append( (5, 6, 7) )
print len(my_tuple)
a) 1 c) 5
b) 2 d) Error
161. What will be the output?
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 c) 33
b) 24 d) 12

Page 18 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

162. What will be the output?


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 c) 33
b) 24 d) 12
163. Which is the correct operator for power(x^y)?
a) X^y c) X^^y
b) X**y d) None of the mentioned
164. Which one of these is floor division?
a) / c) %
b) // d) None of the mentioned
165. What is the order of precedence in python? i) Parentheses ii) Exponential iii) Division iv)
Multiplication v) Addition vi) Subtracti
a) i,ii,iii,iv,v,vi c) ii,i,iv,iii,v,vi
b) ii,i,iii,iv,v,vi d) i,ii,iii,iv,vi,v
166. What is answer of this expression, 22 % 3 is?
a) 7 c) 0
b) 1 d) 5
167. You can perform mathematical operation on String?
a) True b) False
168. Which one of the following have the same precedence?
a) Addition and Subtraction c) a and b
b) Multiplication and Division d) None of the mentioned
169. Is Python case sensitive when dealing with identifier
a) yes c) sometimes only
b) no d) none of the mentioned
170. What is the maximum possible length of an identifier?
a) 31 characters c) 79 characters
b) 63 characters d) none of the mentioned
171. Which of the following is invalid?
a) _a = 1 c) __str__ = 1
b) __a = 1 d) none of the mentioned
172. Which of the following is an invalid variable?
a) my_string_1 c) foo
b) 1st_string d) _

Page 19 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

173. Why are local variable names beginning with an underscore discouraged?
a) they are used to indicate a private variables of a class
b) they confuse the interpreter
c) they are used to indicate global variables
174. Which of the following is not a keyword?
a) eval c) nonlocal
b) assert d) pass
175. All keywords in Python are in
a) lower case c) Capitalized
b) UPPER CASE d) none
176. Which of the following is true for variable names in Python?
a) unlimited length
b) all private members must have leading and trailing underscores
c) underscore and ampersand are the only two special charaters allowed
d) none
177. Which of the following is an invalid statement?
a) abc = 1,000,000 c) a,b,c = 1000, 2000, 3000
b) a b c = 1000 2000 3000 d) a_b_c = 1,000,000
178. Which of the following cannot be a variable?
a) __init__ c) it
b) in d) on
179. Which module in Python supports regular expression?
a) re c) pyregex
b) regex d) none of the mentioned
180. Which of the following creates a pattern object?
a) [Link](str) c) [Link](str)
b) [Link](str) d) [Link](str)
181. What does the function [Link] do?
a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
d) none of the mentioned
182. What does the function [Link] do?
a) matches a pattern at the start of the string
b) matches a pattern at any position in the string
c) such a function does not exist
183. What is the output of the following?
sentence = 'we are humans'
matched = [Link](r'(.*) (.*?) (.*)', sentence)
print([Link]())
a) ('we', 'are', 'humans') c) ('we', 'humans')
b) (we, are, humans) d) 'we are humans'

Page 20 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

184. What is the output of the following?


sentence = 'we are humans'
matched = [Link](r'(.*) (.*?) (.*)', sentence)
print([Link]())
a) ('we', 'are', 'humans') c) ('we', 'humans')
b) (we, are, humans) d) 'we are humans'
185. What is the output of the following?
sentence = 'we are humans'
matched = [Link](r'(.*) (.*?) (.*)', sentence)
print([Link](2))
a) 'are' c) 'humans'
b) 'we' d) 'we are humans'
186. What is the output of the following?
sentence = 'horses are fast'
regex = [Link]('(?P\w+) (?P\w+) (?P\w+)')
matched = [Link](regex, sentence)
print([Link]())
a) {'animal': 'horses', 'verb': 'are', 'adjective': 'fast'}
b) ('horses', 'are', 'fast')
c) 'horses are fast'
d) 'are'
187. What is the output of the following?
sentence = 'horses are fast'
regex = [Link]('(?P\w+) (?P\w+) (?P\w+)')
matched = [Link](regex, sentence)
print([Link]())

a) {'animal': 'horses', 'verb': 'are', 'adjective': 'fast'}


b) ('horses', 'are', 'fast')
c) 'horses are fast'
d) 'are'
188. What is the output of the following?
sentence = 'horses are fast'
regex = [Link]('(?P\w+) (?P\w+) (?P\w+)')
matched = [Link](regex, sentence)
print([Link](2))
a) {'animal': 'horses', 'verb': 'are', 'adjective': 'fast'}
b) ('horses', 'are', 'fast')
c) 'are'
189. What is the output of print 0.1 + 0.2 == 0.3?
a) True c) Machine dependent
b) False d) Error

Page 21 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

190. Which of the following is not a complex number?


a) k = 2 + 3j c) k = 2 + 3l
b) k = complex(2, 3) d) k = 2 + 3J
191. What is the type of inf?
a) Boolean c) Float
b) Integer d) Complex
192. What does ~4 evaluate to?
a) -5 c) -3
b) -4 d) +3
193. What does ~~~~~~5 evaluate to?
a) +5 c) +11
b) 11 d) -5
194. \Which of the following is incorrect?
a) x = 0b101 c) x = 19023
b) x = 0x4f5 d) x = 03964
195. What is the result of cmp(3, 1)?
a) 1 c) True
b) 0 d) False
196. What is the output of the following?
x = ['ab', 'cd']
for i in x:
[Link]()
print(x)
a) ['ab', 'cd'] c) [None, None]
b) ['AB', 'CD'] d) none of the mentioned

197. What is the output of the following?


x = ['ab', 'cd']
for i in x:
[Link]([Link]())
print(x)
a) ['AB', 'CD'] c) ['ab', 'cd']
b) ['ab', 'cd', 'AB', d) none of the mentioned
'CD']
198. What is the output of the following?
i=1
while True:
if i%3 == 0:
break
print(i)
i+=1
a) 1 2 e) error
b) 1 2 3 c) none of the mentioned

Page 22 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

199. What is the output of the following?


i=5
while True:
if i%0O11 == 0:
break
print(i)
i += 1
a) 5 6 7 8 9 10 b) 56
f) 5 6 7 8 c) error
200. What is the output of the following?
i=5
while True:
if i%0O9 == 0:
break
print(i)
i += 1
a) 5 6 7 8
b) 5 6 7 8 9
c) 5 6 7 8 9 10 11 12 13 14 15 ....
g) error
201. What is the output of the following?
i=1
while True:
if i%2 == 0:
break
print(i)
i += 2
a) 1 c) 1 2 3 4 5 6 ...
b) 1 2 h) 1 3 5 7 9 11 ...
202. What is the output of the following?
i=2
while True:
if i%3 == 0:
break
print(i)
i += 2
a) 2 4 6 8 10 ... c) 23
b) 2 4 d) error
203. What is the output of the following?
i=1
while False:
if i%2 == 0:
break
print(i)
i += 2
a) 1 c) 1 2 3 4 ...
b) 1 3 5 7 ... i) none of the mentioned

Page 23 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

204. What is the output of the following?


True = False
while True:
print(True)
break
a) True c) None
b) False d) none of the mentioned
205. What is the output of the following?
i=0
while i < 5:
print(i)
i += 1
if i == 3:
break
else:
print(0)
a) 0 1 2 0 c) error
b) 0 1 2 d) none of the mentioned
206. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
print(i, end = " ")
a) no output j) a a a a a a ...
b) i i i i i i ... c) abcdef
207. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
print('i', end = " ")
a) no output c) a a a a a a ...
b) i i i i i i ... d) abcdef
208. What is the output of the following?
x = "abcdef"
i = "a"
while i in x[:-1]:
print(i, end = " ")
a) a a a a a a b) a a a a a a ... c) a
209. What is the output of the following?
x = "abcdef"
i = "a"
while i in x:
x = x[1:]
print(i, end = " ")

Page 24 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

a) a a a a a a c) no output
b) a d) error
210. What is the output of the following?
x = "abcdef"
i = "a"
while i in x[1:]:
print(i, end = " ")
a) a a a a a a c) no output
b) a d) error
211. What is the output of the following?
x = 'abcd'
for i in x:
print(i)
[Link]()
a) a B C D c) ABCD
b) a b c d d) error
212. What is the output of the following?
x = 'abcd'
for i in x:
print([Link]())
a) a b c d b) aBCD
k) A B C D c) error
213. What is the output of the following?
x = 'abcd'
for i in range(x):
print(i)
a) a b c d c) error
b) 0 1 2 3 d) none of the mentioned
214. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
print([Link]())
a) a b c d c) error
b) 0 1 2 3 d) none of the mentioned
215. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
[Link]()
print (x)
a) a b c d c) error
b) 0 1 2 3 d) none of the mentioned

Page 25 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

216. What is the output of the following?


x = 'abcd'
for i in range(len(x)):
x[i].upper()
print (x)
a) Abcd c) Error
b) ABCD d) none of the mentioned
217. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
i[x].upper()
print (x)
a) abcd c) error
b) ABCD d) none of the mentioned
218. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
x = 'a'
print(x)
a) a c) a a a a
b) abcd abcd abcd d) none of the mentioned
219. What is the output of the following?
x = 'abcd'
for i in range(len(x)):
print(x)
x = 'a'
a) a c) a a a a
b) abcd abcd abcd abcd d) none of the mentioned
220. What is the output of the following?
x = 123
for i in x:
print(i)
a) 1 2 3 c) error
b) 123 d) none of the mentioned
221. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for i in d:
print(i)
a) 0 1 2 c) 0a1b2c
b) a b c d) none of the mentioned
222. What is the output of the following?
d = {0: 'a', 1: 'b', 2: 'c'}
for x, y in [Link]():
print(x, y)
a) 0 1 2 c) 0a1b2c
b) a b c d) none of the mentioned

Page 26 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

223. What is the output of the following?


for i in range(2.0):
print(i)
a) 0.0 1.0 c) error
b) 0 1 d) none of the mentioned
224. What is the output of the following?
for i in range(int(2.0)):
print(i)
a) 0.0 1.0 c) error
b) 0 1 d) none of the mentioned
225. What is the output of the following?
for i in range(float('inf')):
print (i)
a) 0.0 0.1 0.2 0.3 ...
b) 0 1 2 3 ...
c) 0.0 1.0 2.0 3.0 ...
d) none of the mentioned
226. What is the output of the following?
for i in [1, 2, 3, 4] [::-1]:
print (i)
a) 1 2 3 4 c) error
b) 4 3 2 1 d) none of the mentioned
227. What is the output of the following?
for i in ''.join(reversed(list('abcd'))):
print (i)
a) a b c d c) error
b) d c b a d) none of the mentioned
228. What is the output of the following?
for i in 'abcd'[::-1]:
print (i)
a) a b c d c) error
b) d c b a d) none of the mentioned
229. What is the output of the following?
for i in '':
print (i)
a) None c) error
b) (nothing is printed) d) none of the mentioned
230. What is the output of the following?
x=2
for i in range(x):
x += 1
print (x)
a) 0 1 2 3 4 ... c) 34
b) 0 1 d) 0123

Page 27 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

231. What is the output of the following?


x=2
for i in range(x):
x -= 2
print (x)
a) 0 1 2 3 4 ... c) 0
b) 0 -2 d) error
232. What is the output of the following?
for i in range(10):
if i == 5:
break
else:
print(i)
else:
print("Here")
a) 0 1 2 3 4 Here c) 0 1 2 3 4
b) 0 1 2 3 4 5 Here d) 1 2 3 4 5
233. What is the output of the following?
for i in range(5):
if i == 5:
break
else:
print(i)
else:
print("Here")
a) 0 1 2 3 4 Here c) 0 1 2 3 4
b) 0 1 2 3 4 5 Here d) 1 2 3 4 5
234. What is the output of the following?
x = (i for i in range(3))
for i in x:
print(i)
a) 0 1 2 c) 012012
b) Error d) none of the mentioned
235. What is the output of the following?
string = "my name is x"
for i in string:
print (i, end=", ")
a) m, y, , n, a, m, e, , i, s, , x, c) my, name, is, x,
b) m, y, , n, a, m, e, , i, s, , x d) error
236. What is the output of the following?
string = "my name is x"
for i in [Link]():
print (i, end=", ")
a) m, y, , n, a, m, e, , i, s, , x, c) my, name, is, x,
b) m, y, , n, a, m, e, , i, s, , x d) error

Page 28 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

237. What is the output of the following?


a = [0, 1, 2, 3]
for a[-1] in a:
print(a[-1])
a) 0 1 2 3 c) 3 3 3 3
b) 0 1 2 2 d) error
238. What is the output of the following?
a = [0, 1, 2, 3]
for a[0] in a:
print(a[0])
a) 0 1 2 3 d) error
b) 0 1 2 2
c) 3 3 3 3
239. What is the output of the following?
a = [0, 1, 2, 3]
i = -2
for i not in a:
print(i)
i += 1
a) -2 -1 c) error
b) 0 d) none of the mentioned
240. What is the output of the following?
string = "my name is x"
for i in ' '.join([Link]()):
print (i, end=", ")
a) m, y, , n, a, m, e, , i, s, , x, c) my, name, is, x,
b) m, y, , n, a, m, e, , i, s, , x d) error
241. What is the output of the following?
print("xyyzxyzxzxyy".count('xyy', 0, 100))
a) 2 c) 1
b) 0 d) Error
242. What is the output of the following?
print("xyyzxyzxzxyy".count('xyy', 2, 11))
a) 2 c) 1
b) 0 d) error
243. What is the output of the following?
print("xyyzxyzxzxyy".count('xyy', -10, -1))
a) 2 c) 1
b) 0 d) error
244. What is the output of the following?
print('abc'.encode())
a) abc c) b'abc'
b) 'abc' d) h'abc'

Page 29 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

245. What is the output of the following?


print("ab\tcd\tef".expandtabs())
a) ab cd ef c) ab\tcd\tef
b) abcdef d) ab cd ef
246. What is the output of the following?
print("abcdef".find("cd"))
a) True c) 3
b) 2 d) none of the mentioned
247. What is the output of the following?
print("ccdcddcd".find("c"))
a) 4 c) error
b) 0 d) True
248. What is the output of the following?
print("Hello {0} and {1}".format('foo', 'bin'))
a) Hello foo and bin c) error
b) Hello {0} and {1} foo bin d) Hello 0 and 1
249. What is the output of the following?
print("Hello {} and {}".format('foo', 'bin'))
a) Hello foo and bin c) error
b) Hello {} and {} d) Hello and
250. What is the output of the following?
print("Hello {name1} and {name2}".format('foo', 'bin'))
a) Hello foo and bin c) error
b) Hello {name1} and {name2} d) Hello and
251. What is the output of the following?
print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))
a) Hello foo and bin c) error
b) Hello {name1} and {name2} d) Hello and
252. What is the output of the following?
print("Hello {0!r} and {0!s}".format('foo', 'bin'))
a) Hello foo and bin c) Hello foo and 'bin'
b) Hello 'foo' and bin d) error
253. What is the output of the following?
print("Hello {0} and {1}".format(('foo', 'bin')))
a) Hello foo and bin
b) Hello ('foo', 'bin') and ('foo', 'bin')
c) error
d) none of the mentioned
254. What is the output of the following?
print('The sum of {0} and {1} is {2}'.format(2, 10, 12))
a) The sum of 2 and 10 is 12 c) The sum of 0 and 1 is 2
b) error d) none of the mentioned

Page 30 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

255. What is the output of the following?


print('The sum of {0:b} and {1:x} is {2:o}'.format(2, 10, 12))
a) The sum of 2 and 10 is 12 c) The sum of 10 and a is c
b) The sum of 10 and a is 14 d) error
256. What is the output of the following?
print('{:,}'.format(1112223334))
a) 1,112,223,334 c) 1112223334
b) 111,222,333,4 d) error
257. What is the output of the following?
print('{:,}'.format('1112223334'))
a) 1,112,223,334 c) 1112223334
b) 111,222,333,4 d) error
258. What is the output of the following?
print('{:$}'.format(1112223334))
a) 1,112,223,334 c) 1112223334
b) 111,222,333,4 d) error
259. What is the output of the following?
print('{:#}'.format(1112223334))
a) 1,112,223,334 c) 1112223334
b) 111,222,333,4 d) error
260. What is the output of the following?
print('{0:.2}'.format(1/3))
a) 0.333333 c) 0.333333:.2
b) 0.33 d) error
261. What is the output of the following?
print('{0:.2%}'.format(1/3))
a) 0.33 c) 33.33%
b) 0.33% d) 33%
262. What is the output of the following?
print('ab12'.isalnum())
a) True c) None
b) False d) error
263. What is the output of the following?
print('ab'.isalpha())
a) True c) None
b) False d) error
264. What is the output of the following?
print('a B'.isalpha())
a) True c) None
b) False d) error
265. What is the output of the following?
print('0xa'.isdigit())
a) True c) None
b) False d) error

Page 31 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

266. What is the output of the following?


print(''.isdigit())
a) True c) None
b) False d) error
267. What is the output of the following?
print('my_string'.isidentifier())
a) True c) None
b) False d) error
268. What is the output of the following?
print('__foo__'.isidentifier())
a) True c) None
b) False d) error
269. What is the output of the following?
print('for'.isidentifier())
a) True c) None
b) False d) error
270. What is the output of the following?
print('abc'.islower())
a) True c) None
b) False d) error
271. What is the output of the following?
print('a@ 1,'.islower())
a) True c) None
b) False d) error
272. What is the output of the following?
print('1@ a'.isprintable())
a) True c) None
b) False d) error
273. What is the output of the following?
print('''
'''.isspace())
a) True c) None
b) False d) error
274. What is the output of the following?
print('\t'.isspace())
a) True c) None
b) False d) error
275. What is the output of the following?
print('HelloWorld'.istitle())
a) True c) None
b) False d) error

Page 32 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

276. What is the output of the following?


print('Hello World'.istitle())
a) True c) None
b) False d) Error
277. What is the output of the following?
print('Hello!2@#World'.istitle())
a) True c) None
b) False d) error
278. What is the output of the following?
print('1Rn@'.lower())
a) n c) rn
b) 1rn@ d) r
279. What is the output of the following?
print('''
\tfoo'''.lstrip())
a) \tfoo c) foo
b) foo d) none of the mentioned
280. What is the output of the following?
print('xyxxyyzxxy'.lstrip('xyy'))
a) zxxy c) xyxzxxy
b) xyxxyyzxxy d) none of the mentioned
281. What is the output of the following?
print('cba'.maketrans('abc', '123'))
a) {97: 49, 98: 50, 99: 51} c) 321
b) {65: 49, 66: 50, 67: 51} d) 123
282. What is the output of the following?
print('a'.maketrans('ABC', '123'))
a) {97: 49, 98: 50, 99: 51} c) {97: 49}
b) {65: 49, 66: 50, 67: 51} d) 1
283. What is the output of the following?
print('abcdef'.partition('cd'))
a) ('ab', 'ef') b) ('abef') c) ('ab', 'cd', 'ef')
284. What is the output of the following?
print('abcdefcdgh'.partition('cd'))
a) ('ab', 'cd', 'ef', 'cd', 'gh') c) ('abcdef', 'cd', 'gh')
b) ('ab', 'cd', 'efcdgh') d) error
285. What is the output of the following?
print('abcd'.partition('cd'))
a) ('ab', 'cd', "?) c) error
b) ('ab', 'cd') d) none of the mentioned
286. What is the output of the following?
print('cd'.partition('cd'))
a) ('cd') c) ('cd', "?, "?)
b) ("?) d) ("?, 'cd', "?)

Page 33 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

287. What is the output of the following?


print('abef'.partition('cd'))
a) ('abef') c) ('abef', "?, "?)
b) ('abef', 'cd', "?) d) error
288. What is the output of the following?
print('abcdef12'.replace('cd', '12'))
a) ab12ef12 c) ab12efcd
b) abcdef12 d) none of the mentioned
289. What is the output of the following?
print('abcefd'.replace('cd', '12'))
a) ab1ef2 c) ab1efd
b) abcefd d) ab12ed2
290. What is the output of the following?
print('xyyxyyxyxyxxy'.replace('xy', '12', 0))
a) xyyxyyxyxyxxy c) 12yxyyxyxyxxy
b) 12y12y1212x12 d) xyyxyyxyxyx12
291. What is the output of the following?
print('xyyxyyxyxyxxy'.replace('xy', '12', 100))
a) xyyxyyxyxyxxy c) none of the mentioned
b) 12y12y1212x12 d) error
292. What is the output of the following?
print('abcdefcdghcd'.split('cd'))
a) ['ab', 'ef', 'gh'] c) ('ab', 'ef', 'gh')
b) ['ab', 'ef', 'gh', "?] d) ('ab', 'ef', 'gh', "?)
293. What is the output of the following?
print('abcdefcdghcd'.split('cd', 0))
a) ['abcdefcdghcd'] c) error
b) 'abcdefcdghcd' d) none of the mentioned
294. What is the output of the following?
print('abcdefcdghcd'.split('cd', -1))
a) ['ab', 'ef', 'gh'] c) ('ab', 'ef', 'gh')
b) ['ab', 'ef', 'gh', "?] d) ('ab', 'ef', 'gh', "?)
295. What is the output of the following?
print('abcdefcdghcd'.split('cd', 2))
a) ['ab', 'ef', 'ghcd'] c) ['abcdef', 'ghcd']
b) ['ab', 'efcdghcd'] d) none of the mentioned
296. What is the output of the following?
print('ab\ncd\nef'.splitlines())
a) ['ab', 'cd', 'ef'] c) ['ab\n', 'cd\n', 'ef']
b) ['ab\n', 'cd\n', 'ef\n'] d) ['ab', 'cd', 'ef\n']
297. What is the output of the following?
print('Ab!2'.swapcase())
a) AB!@ c) aB!2
b) ab12 d) aB1@

Page 34 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

298. What is the output of the following?


print('ab cd-ef'.title())
a) Ab cd-ef b) Ab Cd-ef c) Ab Cd-Ef
299. What is the output of the following?
print('abcd'.translate('a'.maketrans('abc', 'bcd')))
a) bcde c) error
b) abcd d) none of the mentioned
300. What is the output of the following?
print('abcd'.translate({97: 98, 98: 99, 99: 100}))
a) bcde c) error
b) abcd d) none of the mentioned
301. What is the output of the following?
print('abcd'.translate({'a': '1', 'b': '2', 'c': '3', 'd': '4'}))
a) abcd b) 1234 c) error
302. What is the output of the following?
print('ab'.zfill(5))
a) 000ab c) 0ab00
b) 00ab0 d) ab000
303. What is the output of the following?
print('+99'.zfill(5))
a) 00+99 c) +0099
b) 00099 d) +++99
304. What is the output when following statement is executed ?
"a"+"bc"
a) a c) bca
b) bc d) abc
305. What is the output when following statement is executed ?
"abcd"[2:]
a) a c) cd
b) ab d) dc
306. The output of executing string.ascii_letters can also be achieved by:
a) string.ascii_lowercase_string.digits
b) string.ascii_lowercase+string.ascii_upercase
c) [Link]
d) string.lowercase_string.upercase
307. What arithmetic operators cannot be used with strings?
a) + c) ?=
b) * d) **
308. What is the output when following code is executed?
print r"\nhello"
The output
a) a new line and hello c) the letter r and then hello
b) \nhello d) Error

Page 35 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

309. What is the output when following statement is executed?


print 'new' 'line'
a) Error c) new line
b) newline d) Output equivalent to print 'new\nline'
310. What is the output when following statement is executed?
print '\x97\x98'
a) Error c) _~
b) 97 98 d) \x97\x98
311. What is the output when following code is executed?
str1="helloworld"
str1[::-1]
a) dlrowolleh b) hello c) helloworld
312. What is the output of the following code?
class father:
def __init__(self, param):
self.o1 = param
?
class child(father):
def __init__(self, param):
self.o2 = param
?
obj = child(22)
print "%d %d" % (obj.o1, obj.o2)
a) None None c) 22 None
b) None 22 d) Error is generated
313. What is the output of the following code?
class tester:
def __init__(self, id):
[Link] = str(id)
id="224"
?
temp = tester(12)
print [Link]
a) 224 c) 12
b) Error d) None
314. What is the output of the following code ?
example = "snow world"
print "%s" % example[4:7]
a) wo c) sn
b) world d) rl
315. What is the output of the following code ?
example = "snow world"
example[3] = 's'
print example

Page 36 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

a) snow c) Error
b) snow world d) snos world
316. What is the output of the following code ?
max("what are you")
a) Error c) t
b) u d) y
317. Given a string example="?hello"? what is the output of [Link](l)
a) 2 c) None
b) 1 d) 0
318. What is the output of the following code ?
example = "helle"
[Link]("e")
a) Error c) 1
b) -1 d) 0
319. What is the output when following statement is executed ?
chr(ord('A'))
a) A c) a
b) B d) Error
320. What is the output when following statement is executed ?
print(chr(ord('b')+1))
a) a c) c
b) b d) A
321. Which of the following statement prints hello\example\[Link].?
a) print("hello\example\[Link]"?)
b) print("hello\\example\\[Link]"?)
c) print("hello\"?example\"?[Link]"?)
d) print("hello"?\example"?\[Link]"?)
322. Suppose s is "\t\tWorld\n"?, what is [Link]()?
a) \t\tWorld\n c) \t\tWORLD\n
b) \t\tWorld\n d) World
323. The format function returns:
a) Error c) bool
b) int d) str
324. What is the output of "hello"?+1+2+3?
a) hello123 c) Error
b) hello d) hello6
325. What is the output when following code is executed ?
print("D", end = ' ')
print("C", end = ' ')
print("B", end = ' ')
print("A", end = ' ')
a) DCBA c) D C B A
b) A, B, C, D d) A, B, C, D will be displayed on four lines

Page 37 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

326. What is the output when following statement is executed? (python [Link])
print(format("Welcome", "10s"), end = '#')
print(format(111, "4d"), end = '#')
print(format(924.656, "3.2f"))
a) ???Welcome#?111#924.66 c) Welcome#111#.66
b) Welcome#111#924.66 d) Welcome???#?111#924.66
327. What will be displayed by print(ord('b') ? ord('a'))?
a) 0 c) -1
b) 1 d) 2
328. Say s="?hello"? what will be the return value of type(s)?
a) int c) str
b) bool d) String

329. What is "Hello"?.replace("l"?, "e"?)


a) Heeeo c) Heleo
b) Heelo d) None
330. Suppose i is 5 and j is 4, i + j is same as
a) i.__add(j) c) i.__Add(j)
b) i.__add__(j) d) i.__ADD(j)
331. What is the output of the following code?
class Count:
def __init__(self, count = 0):
self.__count = count
?
c1 = Count(2)
c2 = Count(2)
print(id(c1) == id(c2), end = " ")
?
s1 = "Good"
s2 = "Good"
print(id(s1) == id(s2))
a) True False c) False True
b) True True d) False False
332. What function do you use to read a string?
a) input("Enter a string"?) c) enter("Enter a string"?)
b) eval(input("Enter a string"?)) d) eval(enter("Enter a string"?))
333. Suppose x is 345.3546, what is format(x, "10.3f"?) (_ indicates spac)
a) __345.355 c) ____345.355
b) ___345.355 d) _____345.354
334. What is the output of the following?
print("abc DEF".capitalize())
a) abc def c) Abc def
b) ABC DEF d) Abc Def

Page 38 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

335. What is the output of the following?


print("abc. DEF".capitalize())
a) abc def c) Abc def
b) ABC DEF d) Abc Def
336. What is the output of the following?
print("abcdef".center())
a) cd c) error
b) abcdef d) none of the mentioned
337. What is the output of the following?
print('*', "abcdef".center(7), '*')
a) * abcdef * c) *abcdef *
b) * abcdef * d) * abcdef*
338. What is the output of the following?
print('*', "abcde".center(6), '*', sep='')
a) * abcde * c) *abcde *
b) * abcde * d) * abcde*
339. What is the output of the following?
print("abcdef".center(7, 1))
a) 1abcdef c) abcdef
b) abcdef1 d) error
340. What is the output of the following?
print("abcdef".center(7, '1'))
a) 1abcdef c) abcdef
b) abcdef1 d) error
341. What is the output of the following?
print("abcdef".center(10, '12'))
a) 12abcdef12 c) 1212abcdef
b) abcdef1212 d) error
342. What is the output of the following?
print("xyyzxyzxzxyy".count('yy'))
a) 2 c) error
b) 0 d) none of the mentioned
343. What is the output of the following?
print("xyyzxyzxzxyy".count('yy', 1))
a) 2 c) 1
b) 0 d) none of the mentioned
344. What is the output of the following?
print("xyyzxyzxzxyy".count('yy', 2))
a) 2 c) 1
b) 0 d) none of the mentioned
345. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?
a) [2, 33, 222, 14]
b) Error
c) 25
d) [25, 14, 222, 33, 2]

Page 39 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

346. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]?
a) Error c) 25
b) None d) 2
347. To shuffle the list(say list1) what function do we use?
a) [Link]() c) [Link](list1)
b) shuffle(list1) d) [Link](list1)
348. Suppose list1 is [1, 5, 9], what is sum(list1)?
a) 1 c) 15
b) 9 d) Error
349. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1)?
a) 3 c) 25
b) 5 d) 1
350. Suppose list1 is [2445,133,12454,123], what is max(list1)?
a) 2445 c) 12454
b) 133 d) 123
351. Suppose listExample is ['h','e','l','l','o'], what is len(listExample)?
a) 5 c) None
b) 4 d) Error
352. What is the output when we execute list("hello"?)?
a) ['h', 'e', 'l', 'l', 'o'] c) ['llo']
b) ['hello'] d) ['olleh']
353. What is the output when following code is executed ?
names = ['Amir', 'Bear', 'Charlton', 'Daman']
print names[-1][-1]
a) A c) Error
b) Daman d) n
354. What is the output when following code is executed ?
names1 = ['Amir', 'Bear', 'Charlton', 'Daman']
names2 = names1
names3 = names1[:]
?
names2[0] = 'Alice'
names3[1] = 'Bob'
?
sum = 0
for ls in (names1, names2, names3):
if ls[0] == 'Alice':
sum += 1
if ls[1] == 'Bob':
sum += 10
?
print sum
a) 11 c) 21
b) 12 d) 22

Page 40 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

355. Suppose list1 is [1, 3, 2], What is list1 * 2?


a) [2, 6, 4] c) [1, 3, 2, 1, 3, 2]
b) [1, 3, 2, 1, 3] d) [1, 3, 2, 3, 2, 1]
356. What is the output when following code is executed?
list1 = [11, 2, 23]
list2 = [11, 2, 2]
list1 < list2 is
a) True c) Error
b) False d) None
357. To add a new element to a list we use which command?
a) [Link](5) c) [Link](5)
b) [Link](5) d) [Link](5)
358. To insert 5 to the third position in list1, we use which command?
a) [Link](3, 5) c) [Link](3, 5)
b) [Link](2, 5) d) [Link](3, 5)
359. To remove string "hello"? from list1, we use which command?
a) [Link]("hello"?) c) [Link]("hello"?)
b) [Link](hello) d) [Link]("hello"?)
360. Suppose list1 is [3, 4, 5, 20, 5], what is [Link](5)/?
a) 0 c) 4
b) 1 d) 2
361. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is [Link](5)?
a) 0 c) 1
b) 4 d) 2
362. Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after [Link]()?
a) [3, 4, 5, 20, 5, 25, 1, 3] c) [25, 20, 5, 5, 4, 3, 3, 1]
b) [1, 3, 3, 4, 5, 5, 20, 25] d) [3, 1, 25, 5, 20, 5, 4, 3]
363. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after [Link]([34,
5])?
a) [3, 4, 5, 20, 5, 25, 1, 3, 34, 5] c) [25, 20, 5, 5, 4, 3, 3, 1, 34, 5]
b) [1, 3, 3, 4, 5, 5, 20, 25, 34, 5] d) [1, 3, 4, 5, 20, 5, 25, 3, 34, 5]
364. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after [Link](1)?
a) [3, 4, 5, 20, 5, 25, 1, 3] c) [3, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25] d) [1, 3, 4, 5, 20, 5, 25]
365. Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after [Link]()?
a) [3, 4, 5, 20, 5, 25, 1] c) [3, 5, 20, 5, 25, 1, 3]
b) [1, 3, 3, 4, 5, 5, 20, 25] d) [1, 3, 4, 5, 20, 5, 25]
366. What is the output when following code is executed?
"Welcome to Python".split()
a) ["Welcome"?, "to"?, "Python"?]
b) ("Welcome"?, "to"?, "Python"?)
c) {"Welcome"?, "to"?, "Python"?}
d) "Welcome"?, "to"?, "Python"?

Page 41 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

367. What is the output when following code is executed?


myList = [1, 5, 5, 5, 5, 1]
max = myList[0]
indexOfMax = 0
for i in range(1, len(myList)):
if myList[i] > max:
max = myList[i]
indexOfMax = i
?
print(indexOfMax)
a) 1 c) 3
b) 2 d) 4
368. What is the output when following code is executed?
list1 = [1, 3]
list2 = list1
list1[0] = 4
print(list2)
a) [1, 3] c) [1, 4]
b) [4, 3] d) [1, 3, 4]
369. What is the output when following code is executed?
def f(values):
values[0] = 44
?
v = [1, 2, 3]
f(v)
print(v)
a) [1, 2, 3, 44] b) [44, 2, 3] c) [1, 2, 3]
370. What is the output when following code is executed ?
myList = [1, 2, 3, 4, 5, 6]
for i in range(1, 6):
myList[i - 1] = myList[i]
?
for i in range(0, 6):
print(myList[i], end = " ")
a) 2 3 4 5 6 1 c) 2 3 4 5 6 6
b) 6 1 2 3 4 5 d) 1 1 2 3 4 5
371. What will be the output?
def f(i, values = []):
[Link](i)
return values
?
f(1)
f(2)
v = f(3)
print(v)

Page 42 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

a) [1] [2] [3] c) [1, 2, 3]


b) [1] [1, 2] [1, 2, 3] d) 1 2 3
372. What will be the output?
names1 = ['Amir', 'Bala', 'Chales']
?
if 'amir' in names1:
print 1
else:
print 2
a) None c) 2
b) 1 d) Error
373. What will be the output?
names1 = ['Amir', 'Bala', 'Charlie']
names2 = [[Link]() for name in names1]
?
print names2[2][0]
a) None c) b
b) a d) c
374. To which of the following the "in"? operator can be used to check if an item is in it?
a) Lists c) Set
b) Dictionary d) All of The Above
375. What will be the output?
list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
?
print len(list1 + list2)
a) 2 c) 5
b) 4 d) 8
376. What will be the output?
def addItem(listParam):
listParam += [1]
?
mylist = [1, 2, 3, 4]
addItem(mylist)
print len(mylist)
a) 1 c) 5
b) 4 d) 8
377. What will be the output?
def example(L):
''' (list) -> list
'''
i=0

Page 43 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

result = []
while i < len(L):
[Link](L[i])
i=i+3
return result
a) Return a list containing every third item from L starting at index 0.
b) Return an empty list
c) Return a list containing every third index from L starting at index 0.
d) Return a list containing the items from L starting from index 0, omitting every third item.
378. What will be the output?
veggies = ['carrot', 'broccoli', 'potato', 'asparagus']
[Link]([Link]('broccoli'), 'celery')
print(veggies)
a) ['carrot', 'celery', 'broccoli', 'potato', 'asparagus'] Correct 1.00
b) ['carrot', 'celery', 'potato', 'asparagus']
c) ['carrot', 'broccoli', 'celery', 'potato', 'asparagus']
d) ['celery', 'carrot', 'broccoli', 'potato', 'asparagus']
379. What will be the output?
m = [[x, x + 1, x + 2] for x in range(0, 3)]
a) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
b) [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
c) [1, 2, 3, 4, 5, 6, 7, 8, 9]
d) [0, 1, 2, 1, 2, 3, 2, 3, 4]
380. How many elements are in m?
m = [[x, y] for x in range(0, 4) for y in range(0, 4)]
a) 8 c) 16
b) 12 d) 32
381. What will be the output?
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
?
v = values[0][0]
for row in range(0, len(values)):
for column in range(0, len(values[row])):
if v < values[row][column]:
v = values[row][column]
?
print(v)
a) 3 c) 6
b) 5 d) 33
382. What will be the output?
values = [[3, 4, 5, 1 ], [33, 6, 1, 2]]
?
for row in values:
[Link]()

Page 44 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

for element in row:


print(element, end = " ")
print()
a) The program prints two rows 3 4 5 1 followed by 33 6 1 2
b) The program prints on row 3 4 5 1 33 6 1 2
c) The program prints two rows 3 4 5 1 followed by 33 6 1 2
d) The program prints two rows 1 3 4 5 followed by 1 2 6 33
383. What is the output?
matrix = [[1, 2, 3, 4],
[4, 5, 6, 7],
[8, 9, 10, 11],
[12, 13, 14, 15]]
?
for i in range(0, 4):
print(matrix[i][1], end = " ")
a) 1 2 3 4 c) 1 3 8 12
b) 4 5 6 7 d) 2 5 9 13
384. What will be the output?
def m(list):
v = list[0]
for e in list:
if v < e: v = e
return v
?
values = [[3, 4, 5, 1], [33, 6, 1, 2]]
?
for row in values:
print(m(row), end = " ")
a) 3 33 c) 5 6
b) 1 1 d) 5 33
385. What will be the output?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
?
print(data[1][0][0])
a) 1 c) 4
b) 2 d) 5
386. What will be the output?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
?
def ttt(m):
v = m[0][0]
?

Page 45 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

for row in m:
for element in row:
if v < element: v = element
?
return v
?
print(ttt(data[0]))
a) 1 c) 4
b) 2 d) 5
387. What will be the output?
points = [[1, 2], [3, 1.5], [0.5, 0.5]]
[Link]()
print(points)
a) [[1, 2], [3, 1.5], [0.5, 0.5]] c) [[0.5, 0.5], [1, 2], [3, 1.5]]
b) [[3, 1.5], [1, 2], [0.5, 0.5]] d) [[0.5, 0.5], [3, 1.5], [1, 2]]
388. What will be the output?
points = [[1, 2], [3, 1.5], [0.5, 0.5]]
[Link]()
print(points)
a) [[1, 2], [3, 1.5], [0.5, 0.5]] c) [[0.5, 0.5], [1, 2], [3, 1.5]]
b) [[3, 1.5], [1, 2], [0.5, 0.5]] d) [[0.5, 0.5], [3, 1.5], [1, 2]]
389. Suppose d = {"john"?:40, "peter"?:45}, what happens when retieving a value using
d["susan"?]?
a) Since "susan"? is not a value in the set, Python raises a KeyError exception.
b) It is executed fine and no exception is raised, and it returns None.
c) Since "susan"? is not a key in the set, Python raises a KeyError exception.
390. What are the keys?
d = {"john":40, "peter":45}
a) "john"?, 40, 45, and "peter"? c) 40 and 45
b) "john"? and "peter"? d) d = (40:"?john"?, 45:"?peter"?)
391. What will be the output?
d = {"john":40, "peter":45}
"john" in d
a) True c) None
b) False d) Error
392. What will be the output?
d1 = {"john":40, "peter":45}
d2 = {"john":466, "peter":45}
d1 > d2
a) True c) Error
b) False d) None

Page 46 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

393. What is the output?


d = {"john":40, "peter":45}
d["john"]
a) 40 c) "john"?
b) 45 d) "peter"?
394. Suppose d = {"john"?:40, "peter"?:45}, to delete the entry for "john"? what command do
we use?
a) [Link]("john"?:40) c) del d["john"?]
b) [Link]("john"?) d) del d("john"?:40)
395. Suppose d = {"john"?:40, "peter"?:45}, to obtain the number of entries in dictionary what
command do we use
a) [Link]() c) size(
b) lend) d) d) [Link]()
396. What will be the output?
d = {"john":40, "peter":45}
print(list([Link]()))
a) ["john"?, "peter"?] c) ("john"?, "peter"?)
b) ["john"?:40, "peter"?:45] d) ("john"?:40, "peter"?:45)
397. What does [Link] contain?
a) the name of the operating system dependent module imported
b) the address of the module os
c) error, it should've been [Link]()
d) none of the mentioned
398. What does print([Link]()) print?
a) the group id of the current process
b) the user id of the current process
c) both the group id and the user of the current process
d) none of the mentioned
399. What does [Link]() return?
a) name of the current user logged in
b) name of the superuser
c) gets a form to login as a different user
400. What does [Link](f) do?
a) terminate the process f
b) close the file descriptor f
c) return an integer telling how close the file pointer is to the end of file
401. What does [Link](fd, mode) do?
a) change permission bits of the file
b) change permission bits of the directory
c) change permission bits of either the file or the directory

Page 47 of 48
G-TEC EDUCATION
ISO 9001:2015 CERTIFIED
PYTHON BASICS - QUESTION BANK

402. Which of the following functions can be used to read data from a file using a file
descriptor?
a) [Link]() c) os.quick_read()
b) [Link]() d) [Link]()
403. Which of the following returns a string that represents the present working directory?
a) [Link]() c) [Link]()
b) [Link]() d) [Link]()
404. What does [Link]() do?
a) create a symbolic link c) create a soft link
b) create a hard link d) none of the mentioned
405. Which of the following can be used to create a directory?
a) [Link]() c) os.create_dir()
b) os.creat_dir() d) os.make_dir()
406. Which of the following can be used to create a symbolic link?
a) [Link]() c) [Link]()
b) os.symb_link() d) [Link]()

Page 48 of 48

You might also like