Here is an interesting Python Multiple choice questions Quiz. Attempting this MCQ will help you to evaluate your knowledge and skills.
Table of Contents
A. What will be the output of the following Python function?
re.findall(“hello world”, “hello”, 1)
- [“hello”]
- [ ]
- hello
- hello world
B. Which of the following functions results in a case insensitive matching?
- re.A
- re.U
- re.I
- re.X
C. Choose the function whose output can be: <_sre.SRE_Match object; span=(4, 8), match=’aaaa’>
- re.search(‘aaaa’, “alohaaaa”, 0)
- re.match(‘aaaa’, “alohaaaa”, 0)
- re.match(‘aaa’, “alohaaa”, 0)
- re.search(‘aaa’, “alohaaa”, 0)
D. What will be the output of the following Python code?
x = 50
def func(x):
x = 2
func(x)
print(‘x is now’, x)
- x is now 50
- x is now 2
- x is now 100
- None of the mentioned
E. What will be the output of the following Python code?
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)
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
d) None of the mentioned
F. What will be the output of the following Python code?
def a(b):
b = b + [5]
c = [1, 2, 3, 4]
a(c)
print(len(c))
- 4
- 5
- 1
- An exception is thrown
G. What will be the output of the following Python code?
a=10
b=20
def change():
global b
a=45
b=56
change()
print(a)
print(b)
a)
10
56
b)
45
56
c)
10
20
d) Syntax Error
H. How do you get the name of a file from a file object (fp)?
- fp.name
- fp.file(name)
- self.__name__(fp)
- fp.__name__()
I. How do you rename a file?
- fp.name = ‘new_name.txt’
- os.rename(existing_name, new_name)
- os.rename(fp, new_name)
- os.set_name(existing_name, new_name)
J. Which function is used to read a single line from a file?
- Readline()
- Readlines()
- Readstatement()
- Readfullline()
K. Which function is used to write a list of strings in a file?
- writeline()
- writelines()
- writestatement()
- writefullline()
L. What will be the output of the following Python code? (If entered name is dbms)
import sys
print ‘Enter your name: ‘,
name = ”
while True:
c = sys.stdin.read(1)
if c == ‘\n’:
break
name = name + c
print ‘Your name is:’, name
- dbms
- dbms, dbms
- dbm
- None of the mentioned
M. Correct syntax of file.writelines() is?
- file.writelines(sequence)
- fileObject.writelines()
- fileObject.writelines(sequence)
- none of the mentioned
N. What will be the output of the following Python code?
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(elements, incr)))
- [1, 2, 3]
- [0, 1, 2]
- error
- none of the mentioned
O. What will be the output of the following Python code?
x = [12.1, 34.0]
print(len(‘ ‘.join(list(map(str, x)))))
- 6
- 8
- 9
- error