Q1. |
Which of the following is the use of function in python? Answer: a |
||||
Q2. |
2.
Which keyword is used for function? Answer: c |
||||
Q3. |
What
will be the output of the following Python code? def sayHello(): print('Hello World!') sayHello() sayHello()
Answer:
a |
||||
Q4. |
What
will be the output of the following Python code? 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')
print
Max(3, 4) a) 3 b) 4 c)
4 is maximum d) None of
the mentioned Answer:
c |
||||
Q5. |
5.
What will be the output of the following Python code? x =50 def func(x): print('x is', x) x =2 print('Changed local x to', x) func(x) print('x is now', x)
Answer:
a |
||||
Q6. |
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)
Answer:
b |
||||
Q7. |
What
will be the output of the following Python code? def say(message, times =1): print(message * times) say('Hello') say('World',5)
Answer : c |
||||
Q8. |
What
will be the output of the following Python code? 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)
Answer:
c |
||||
Q9. |
What
will be the output of the following Python code? 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 Answer:
b |
||||
Q10.
|
Which
of the following is a feature of DocString? |
||||
Q11.
|
Which
are the advantages of functions in python? |
||||
Q12.
|
What are the two main types of functions? |
||||
Q13.
|
Where
is function defined? Answer: d |
||||
Q14.
|
What
is called when a function is defined inside a class? Answer: d |
||||
Q15.
|
Which of the following is the use of id()
function in python? |
||||
Q16.
|
Which
of the following refers to mathematical function? |
||||
Q17.
|
What will be the output of the following Python
code? def cube(x): return x * x * x x =cube(3) print x
a) 9 b) 3 c)
27 d)
30 Answer: c |
||||
Q18.
|
What will be the output of the following Python
code? def C2F(c): return c * 9/5 + 32 print C2F(100) print C2F(0)
Answer: a |
||||
Q19.
|
What
will be the output of the following Python code? def power(x, y=2):
r =1
for i in range(y):
r = r * x
return r
print (power(3))
print (power(3,3))
Answer:
b |
||||
Q20.
|
What is a variable defined outside a function
referred to as? |
||||
Q21.
|
What
will be the output of the following Python 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 |
||||
Q22.
|
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))
a) 4 b) 5 c)
1 d)
An exception is thrown |
||||
Q23.
|
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)
Answer:
a |
||||
Q24.
|
What will be the output of the following Python
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) 1 2 |
||||
Q25.
|
What will be the output of the following Python
code? def change(one, *two): print(type(two)) change(1,2,3,4)
a)
Integer
b)
Tuple |
||||
Q26.
|
If a
function doesn’t have a return statement, which of the following does the
function return? |
||||
Q27.
|
What will be the output of the following Python
code? def display(b, n): while n >0: print(b,end="") n=n-1 display('z',3)
a)
zzz
b) zz |
No comments:
Post a Comment