- Which keyword is used to define a function in Python?
View Answer
Correct answer: C — def
- What will be printed?
1 def greet(): 2 return "Hello Eduinq" 3 print(greet()) View Answer
Correct answer: A — Hello Eduinq
- Which of the following is used to call a function?
View Answer
Correct answer: A — function_name()
- What is the default return value of a function if no return statement is given?
View Answer
Correct answer: A — None
- Which of the following is used to define anonymous functions?
View Answer
Correct answer: B — lambda
- What will be printed?
1 def add(a,b): 2 return a+b 3 print(add(2,3)) View Answer
Correct answer: A — 5
- Which of the following is used to pass variable number of arguments?
View Answer
Correct answer: C — Both A and B
- What is the output of print(type(lambda x: x+1))?
View Answer
Correct answer: A — <class 'function'>
- Which of the following is used to define recursion?
View Answer
Correct answer: A — Function calling itself
- What will be printed?
1 def fact(n): 2 if n==0: 3 return 1 4 else: 5 return n*fact(n-1) 6 print(fact(3)) View Answer
Correct answer: A — 6
- Which of the following is used to define default arguments?
View Answer
Correct answer: A — def func(a=10)
- What is the output of print(len([lambda x: x**2 for x in range(3)]))?
View Answer
Correct answer: B — 3
- Which of the following is used to define keyword arguments?
View Answer
Correct answer: A — func(a=10)
- What will be printed?
1 def greet(name="Eduinq"): 2 return "Hello " + name 3 print(greet()) View Answer
Correct answer: A — Hello Eduinq
- Which of the following is used to define nested functions?
View Answer
Correct answer: A — Function inside function
- What is the output of print((lambda x,y: x*y)(2,3))?
View Answer
Correct answer: A — 6
- Which of the following is used to define docstring?
View Answer
Correct answer: A — """string"""
- What will be printed?
1 def square(x): 2 """Eduinq function""" 3 return x*x 4 print(square.__doc__) View Answer
Correct answer: A — Eduinq function
- Which of the following is used to return multiple values?
View Answer
Correct answer: D — All of the above
- What is the output of print((lambda x: x+10)(5))?
View Answer
Correct answer: A — 15
- Which of the following is used to define function scope?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 x = 10 2 def func(): 3 global x 4 x = 20 5 func() 6 print(x) View Answer
Correct answer: B — 20
- Which of the following is used to define function with keyword arguments?
View Answer
Correct answer: A — def func(**kwargs)
- What is the output of print((lambda x: x**2)(4))?
View Answer
Correct answer: A — 16
- Which of the following is used to define recursive factorial function?
View Answer
Correct answer: A — def fact(n): return n*fact(n-1)
- What will be printed?
1 def func(a,b=5): 2 return a+b 3 print(func(3)) View Answer
Correct answer: A — 8
- Which of the following is used to define function with variable arguments?
View Answer
Correct answer: C — Both A and B
- What is the output of print((lambda x,y: x+y)(2,3))?
View Answer
Correct answer: A — 5
- Which of the following is used to define recursive Fibonacci function?
View Answer
Correct answer: A — def fib(n): return fib(n-1)+fib(n-2)
- What will be printed?
1 def fib(n): 2 if n<=1: 3 return n 4 else: 5 return fib(n-1)+fib(n-2) 6 print(fib(5)) View Answer
Correct answer: A — 5
- Which of the following is used to define function with default keyword arguments?
View Answer
Correct answer: A — def func(a=10,b=20)
- What is the output of print((lambda x: x*2)(5))?
View Answer
Correct answer: A — 10
- Which of the following is used to define recursive sum function?
View Answer
Correct answer: A — def sum(n): return n+sum(n-1)
- What will be printed?
1 def sum(n): 2 if n==0: 3 return 0 4 else: 5 return n+sum(n-1) 6 print(sum(3)) View Answer
Correct answer: A — 6
- Which of the following is used to define recursive power function?
View Answer
Correct answer: A — def power(n): return n*power(n-1)
- What will be printed?
1 def power(n): 2 if n==0: 3 return 1 4 else: 5 return 2*power(n-1) 6 print(power(3)) View Answer
Correct answer: A — 8
- Which of the following is used to define recursive string reversal?
View Answer
Correct answer: A — def rev(s): return rev(s[1:])+s[0]
- What will be printed?
1 def rev(s): 2 if len(s)==0: 3 return s 4 else: 5 return rev(s[1:])+s[0] 6 print(rev("Eduinq")) View Answer
Correct answer: A — qniudE
- Which of the following is used to define recursive sum of digits?
View Answer
Correct answer: A — def sumd(n): return n%10+sumd(n//10)
- What will be printed?
1 def sumd(n): 2 if n==0: 3 return 0 4 else: 5 return n%10+sumd(n//10) 6 print(sumd(123)) View Answer
Correct answer: A — 6
- Which of the following is used to define recursive length of string?
View Answer
Correct answer: A — def length(s): return 1+length(s[1:])
- What will be printed?
1 def length(s): 2 if s=="": 3 return 0 4 else: 5 return 1+length(s[1:]) 6 print(length("Eduinq")) View Answer
Correct answer: A — 6
- Which of the following is used to define recursive maximum in list?
View Answer
Correct answer: A — def maxlist(l): return max(l[0],maxlist(l[1:]))
- What will be printed?
1 def maxlist(l): 2 if len(l)==1: 3 return l[0] 4 else: 5 return max(l[0],maxlist(l[1:])) 6 print(maxlist([1,5,3])) View Answer
Correct answer: A — 5
- Which of the following is used to define recursive minimum in list?
View Answer
Correct answer: A — def minlist(l): return min(l[0],minlist(l[1:]))
- What will be printed?
1 def minlist(l): 2 if len(l)==1: 3 return l[0] 4 else: 5 return min(l[0],minlist(l[1:])) 6 print(minlist([1,5,3])) View Answer
Correct answer: A — 1
- Which of the following is used to define recursive palindrome check?
View Answer
Correct answer: A — def pal(s): return s==s[::-1]
- What will be printed?
1 def pal(s): 2 return s==s[::-1] 3 print(pal("Eduinq")) View Answer
Correct answer: B — False
- Which of the following is used to define recursive binary search?
View Answer
Correct answer: A — def bsearch(l,x): return bsearch(l[:mid],x) or bsearch(l[mid:],x)
- What will be printed?
1 def bsearch(l,x): 2 if len(l)==0: 3 return False 4 mid=len(l)//2 5 if l[mid]==x: 6 return True 7 elif l[mid]>x: 8 return bsearch(l[:mid],x) 9 else: 10 return bsearch(l[mid+1:],x) 11 print(bsearch([1,2,3,4,5],3)) View Answer
Correct answer: A — True