Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Python Question and Answers - Built-In Functions - 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Python Question and Answers – Built-in Functions – 1

This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Built-in
Functions – 1”.

1. Which of the following functions is a built-in function in python?


a) seed()
b) sqrt()
c) factorial()
d) print()

2. What is the output of the expression:

round(4.576)
a) 4.5
b) 5
c) 4
d) 4.6

3. The function pow(x,y,z) is evaluated as:


a) (x**y)**z
b) (x**y) / z
c) (x**y) % z
d) (x**y)*z

4. What is the output of the function shown below?

all([2,4,0,6])
a) Error
b) True
c) False
c) 0

5. What is the output of the expression?

round(4.5676,2)?
a) 4.5
b) 4.6
c) 4.57
d) 4.56

6. What is the output of the following function?

any([2>8, 4>2, 1>2])


a) Error
b) True
c) False
d) 4>2

7. What is the output of the function shown below?


import math
abs(math.sqrt(25))
a) Error
b) -5
c) 5
d) 5.0

8. What are the outcomes of the functions shown below?

sum(2,4,6)
sum([1,2,3])
a) Error, 6
b) 12, Error
c) 12, 6
d) Error, Error

9. What is the output of the function:

all(3,0,4.2)
a) True
b) False
c) Error
d) 0

10. What is the output of the functions shown below?

min(max(False,-3,-4), 2,7)
a) 2
b) False
c) -3
d) -4

Python Question and Answers – Built-in Functions – 2


This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Built-in
Functions – 2”.

1. What are the outcomes of the following functions?

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

3. What is the output of the function complex() ?


a) 0j
b) 0+0j
c) 0
d) Error

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)

5. What is the output of the functions shown below?

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

7. What is the output of the function shown below?

list(enumerate([2, 3]))
a) Error
b) [(1, 2), (2, 3)]
c) [(0, 2), (1, 3)]
d) [(2, 3)]

8. What are the outcomes of the function shown below?

x=3
eval('x^2')
a) Error
b) 1
c) 9
d) 6

9. What is the output of the functions shown below?

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()

Python Question and Answers – Built-in Functions – 3


This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Built-in
Functions – 3”.

1. Which of the following functions accepts only integers as arguments?


a) ord()
b) min()
c) chr()
d) any()

2. Suppose there is a list such that: l=[2,3,4].


If we want to print this list in reverse order, which of the following methods should be used?
a) reverse(l)
b) list(reverse[(l)])
c) reversed(l)
d) list(reversed(l))

3. The output of the function:

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

5. What is the output of the functions shown below?

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()

7. What is the output of the function shown below?

hex(15)
a) f
b) 0xF
c) 0Xf
d) 0xf

8. Which of the following functions does not throw an error?


a) ord()
b) ord(‘ ‘)
c) ord(”)
d) ord(“”)

9. What is the output of the function:


len(["hello",2, 4, 6])
a) 4
b) 3
c) Error
d) 6

10. What is the output of the function shown below?

oct(7)
oct(‘7’)
a) Error
07
b) 0o7
Error
c) 0o7
Error
d) 07
0o7

Python Questions and Answers – Function – 1


This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Function –
1”.

1. 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
d) All of the mentioned

2. Which keyword is use for function?


a) Fun
b) Define
c) Def
d) Function

3. What is the output of the below program?

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?

def printMax(a, b):


if a > b:
print(a, 'is maximum')
elif a == b:
print(a, 'is equal to', b)
else:
print(b, 'is maximum')
printMax(3, 4)
a) 3
b) 4
c) 4 is maximum
d) None of the mentioned

5. 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

6. 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)
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?

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
HelloHelloHelloHelloHello

8. 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

d) None of the mentioned

9. What is the output of below program?

def maximum(x, y):


if x > y:
return x
elif x == y:
return 'The numbers are equal'
else:
return y

print(maximum(2, 3))
a) 2
b) 3
c) The numbers are equal
d) None of the mentioned

10. 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) Docstrings can be accessed by the __doc__ attribute on objects
d) All of the mentioned

Python Questions and Answers – Function – 2


This set of Python Questions for entrance examinations focuses on “Functions”.

1. Which are the advantages of functions in python?


a) Reducing duplication of code
b) Decomposing complex problems into simpler pieces
c) Improving clarity of the code
d) All of the mentioned

2. What are the two main types of functions?


a) Custom function
b) Built-in function & User defined function
c) User function
d) System function

3. Where is function defined?


a) Module
b) Class
c) Another function
d) All of the mentioned

4. What is called when a function is defined inside a class?


a) Module
b) Class
c) Another function
d) Method

5. 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) All of the mentioned
d) None of the mentioned

6. Which of the following refers to mathematical function?


a) sqrt
b) rhombus
c) add
d) rhombus

7. What is the output of below program?

def cube(x):
return x * x * x
x = cube(3)
print x
a) 9
b) 3
c) 27
d) 30

8. What is the output of the below program?

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

9. What is the output of the below program?

def power(x, y=2):


r=1
for i in range(y):
r=r*x
return r
print power(3)
print power(3, 3)
a) 212
32
b) 9
27
c) 567
98
d) None of the mentioned

10. What is the output of the below program?

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

Python Questions and Answers – Function – 3


This set of Python Questions for campus interview focuses on “Functions”.

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

2. What is the output of this program?

y=6
z = lambda x: x * y
print z(8)
a) 48
b) 14
c) 64
d) None of the mentioned

3. What is the output of below program?

lamb = lambda x: x ** 3
print(lamb(5))
a) 15
b) 555
c) 125
d) None of the mentioned

4. Does Lambda contains return statements?


a) True
b) False

5. Lambda is a statement.
a) True
b) False
6. Lambda contains block of statements
a) True
b) False

7. What is the output of below program?

def f(x, y, z): return x + y + z


f(2, 30, 400)
a) 432
b) 24000
c) 430
d) No output

8. 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
b) Sir Arthur
c) Arthur
d) None of the mentioned

9. What is the output of this program?

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

10. 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
d) None of the mentioned

Python Questions and Answers – Function – 4


This set of Python Multiple Choice Questions & Answers (MCQs) focuses on “Function –
4”.

1. What is a variable defined outside a function referred to as?


a) A static variable
b) A global variable
c) A local variable
d) An automatic variable

2. What is a variable defined inside a function referred to as?


a) A global variable
b) A volatile variable
c) A local variable
d) An automatic variable

3. What is the output of the following code?

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

4. What is the output of the following piece of code?

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

5. What is the output of the following 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

6. What is the output of the following code?

def change(i = 1, j = 2):


i=i+j
j=j+1
print(i, j)
change(j = 1, i = 2)
a) An exception is thrown because of conflicting values
b) 12
c) 33
d) 32

7. What is the output of the following code?

def change(one, *two):


print(type(two))
change(1,2,3,4)
a) Integer
b) Tuple
c) Dictionary
d) An exception is thrown

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

9. What is the output of the following code?

def display(b, n):


while n > 0:
print(b,end="")
n=n-1
display('z',3)
a) zzz
b) zz
c) An exception is executed
d) Infinite loop

10. What is the output of the following piece of code?

def find(a, **b):


print(type(b))
find('letters',A='1',B='2')
a) String
b) Tuple
c) Dictionary
d) An exception is thrown

You might also like