Python Question and Answers - Built-In Functions - 1
Python Question and Answers - Built-In Functions - 1
Python Question and Answers - Built-In Functions - 1
This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Built-in
Functions – 1”.
round(4.576)
a) 4.5
b) 5
c) 4
d) 4.6
all([2,4,0,6])
a) Error
b) True
c) False
c) 0
round(4.5676,2)?
a) 4.5
b) 4.6
c) 4.57
d) 4.56
sum(2,4,6)
sum([1,2,3])
a) Error, 6
b) 12, Error
c) 12, 6
d) Error, Error
all(3,0,4.2)
a) True
b) False
c) Error
d) 0
min(max(False,-3,-4), 2,7)
a) 2
b) False
c) -3
d) -4
chr(‘97’)
chr(97)
a) a
Error
b) ‘a’
a
c) Error
a
d) Error
Error
2. What is the output of the following function?
complex(1+2j)
a) Error
b) 1
c) 2j
d) 1+2j
4. The function divmod(a,b), where both ‘a’ and ‘b’ are integers is evaluated as:
a) (a%b, a//b)
b) (a//b, a%b)
c) (a//b, a*b)
c) (a/b, a%b)
divmod(10.5,5)
divmod(2.4,1.2)
a) (2.00, 0.50)
(2.00, 0.00)
b) (2, 0.5)
(2, 0)
c) (2.0, 0.5)
(2.0, 0.0)
d) (2, 0.5)
(2)
6. The function complex(‘2-3j’) is valid but the function complex(‘2 – 3j’) is invalid. State
whether this statement is true or false.
a) True
b) False
list(enumerate([2, 3]))
a) Error
b) [(1, 2), (2, 3)]
c) [(0, 2), (1, 3)]
d) [(2, 3)]
x=3
eval('x^2')
a) Error
b) 1
c) 9
d) 6
float('1e-003')
float('2e+003')
a) 3.00
300
b) 0.001
2000.0
c) 0.001
200
d) Error
2003
10. Which of the following functions does not necessarily accept only iterables as arguments?
a) enumerate()
b) all()
c) chr()
d) max()
float(' -12345\n')
(Note that the number of blank spaces before the number is 5)
a) -12345.0 (5 blank spaces before the number)
b) -12345.0
c) Error
d) -12345.000000000…. (infinite decimal places)
4. What is the output of the functions shown below?
ord(65)
ord(‘A’)
a) A
65
b) Error
65
c) A
Error
c) Error
Error
float(‘-infinity’)
float(‘inf’)
a) –inf
inf
b) –infinity
inf
c) Error
Error
d) Error
Junk value
6. Which of the following functions will not result in an error when no arguments are passed
to it?
a) min()
b) divmod()
c) all()
d) float()
hex(15)
a) f
b) 0xF
c) 0Xf
d) 0xf
oct(7)
oct(‘7’)
a) Error
07
b) 0o7
Error
c) 0o7
Error
d) 07
0o7
def sayHello():
print('Hello World!')
sayHello()
sayHello()
a) Hello World!
Hello World!
b) ‘Hello World!’
‘Hello World!’
c) Hello
Hello
d) None of the mentioned
4. What is the output of the below program?
x = 50
def func(x):
print('x is', x)
x=2
print('Changed local x to', x)
func(x)
print('x is now', x)
a) x is now 50
b) x is now 2
c) x is now 100
d) None of the mentioned
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
7. What is the output of below program?
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
print(maximum(2, 3))
a) 2
b) 3
c) The numbers are equal
d) None of the mentioned
def cube(x):
return x * x * x
x = cube(3)
print x
a) 9
b) 3
c) 27
d) 30
def C2F(c):
return c * 9/5 + 32
print C2F(100)
print C2F(0)
a) 212
32
b) 314
24
c) 567
98
d) None of the mentioned
def sum(*args):
'''Function returns the sum
of all values'''
r=0
for i in args:
r += i
return r
print sum.__doc__
print sum(1, 2, 3)
print sum(1, 2, 3, 4, 5)
a) 6
15
b) 6
100
c) 123
12345
d) None of the mentioned
1. Python supports the creation of anonymous functions at runtime, using a construct called
__________
a) Lambda
b) pi
c) anonymous
d) None of the mentioned
y=6
z = lambda x: x * y
print z(8)
a) 48
b) 14
c) 64
d) None of the mentioned
lamb = lambda x: x ** 3
print(lamb(5))
a) 15
b) 555
c) 125
d) None of the mentioned
5. Lambda is a statement.
a) True
b) False
6. Lambda contains block of statements
a) True
b) False
def writer():
title = 'Sir'
name = (lambda x:title + ' ' + x)
return name
who = writer()
who('Arthur')
a) Arthur Sir
b) Sir Arthur
c) Arthur
d) None of the mentioned
L = [lambda x: x ** 2,
lambda x: x ** 3,
lambda x: x ** 4]
for f in L:
print(f(3))
a) 27
81
343
b) 6
9
12
c) 9
27
81
d) None of the mentioned
i=0
def change(i):
i=i+1
return i
change(1)
print(i)
a) 1
b) Nothing is displayed
c) 0
d) An exception is thrown
def a(b):
b = b + [5]
c = [1, 2, 3, 4]
a(c)
print(len(c))
a) 4
b) 5
c) 1
d) An exception is thrown
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
8. If a function doesn’t have a return statement, which of the following does the function
return?
a) int
b) null
c) None
d) An exception is thrown without the return statement