0% found this document useful (0 votes)
4 views8 pages

Python Control Structure MCQ

The document consists of a series of multiple-choice questions related to Python functions, covering topics such as function definition, return values, variable scope, and function arguments. Each question includes options for answers, testing knowledge on Python syntax and behavior. The document serves as a quiz or study guide for understanding Python functions.

Uploaded by

Chithra Robinson
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views8 pages

Python Control Structure MCQ

The document consists of a series of multiple-choice questions related to Python functions, covering topics such as function definition, return values, variable scope, and function arguments. Each question includes options for answers, testing knowledge on Python syntax and behavior. The document serves as a quiz or study guide for understanding Python functions.

Uploaded by

Chithra Robinson
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. Which keyword is used to define a function in Python?

a) func
b) define
c) def
d) function
2. Output?

def greet():
print("Hi")
greet()

a) Hi
b) greet
c) None
d) Error

3. What is the default return value of a function without a return statement?


a) 0
b) ""
c) None
d) Undefined
4. Output?

def add(a, b):


return a + b
print(add(2, 3))

a) 5
b) 23
c) Error
d) None

5. A function inside another function is called?


a) Inner function
b) Nested function
c) Lambda function
d) Sub function
6. *args is used for?
a) Variable length arguments
b) Keyword arguments
c) Default arguments
d) Required arguments
7. Output?

def fun(x=5):
print(x)
fun()

a) 0
b) 5
c) None
d) Error

8. Which syntax is correct for defining a function?


a) function myfunc():
b) def myfunc:
c) def myfunc():
d) func myfunc()
9. Output?

def test(a, b=2):


return a * b
print(test(3))

a) 6
b) 5
c) None
d) Error

10. Which keyword is used to exit a function?


a) stop
b) exit
c) return
d) break
11. Calling a function before defining it results in?
a) Works fine
b) SyntaxError
c) NameError
d) ValueError
12. Output?

def f():
pass
print(f())
a) pass
b) None
c) ""
d) Error

13. Which is NOT a valid function name in Python?


a) my_func
b) func1
c) 1func
d) _func

14. Output?

def f():
return "Hello"
print(f)
a) Hello
b) <function f>
c) None
d) Error

15. Output?

def f():
return "Hi"
print(f())
a) Hi
b) None
c) Error
d) f

16. **kwargs is used for?


a) Variable length arguments
b) Keyword arguments
c) Default arguments
d) Required arguments

17. Output?

def add(*args):
return sum(args)
print(add(1, 2, 3))
a) 123
b) 6
c) Error
d) None

18. Can a function return multiple values?


a) Yes
b) No
c) Only integers
d) Only strings

19. Output?

def swap(a, b):


return b, a
x, y = swap(1, 2)
print(x, y)
a) 1 2
b) 2 1
c) (2, 1)
d) Error

20. Output?

def test(x):
x = x + 1
return x
print(test(5))
a) 6
b) 5
c) Error
d) None
21. Which keyword is used for anonymous functions?
a) lambda
b) def
c) func
d) ann

22. Output?

f = lambda x: x * x
print(f(3))
a) 6
b) 9
c) 3
d) Error

23. Output?

def outer():
def inner():
return "Inner"
return inner()
print(outer())
a) Inner
b) outer
c) None
d) Error

24. Output?

def f(a, b, c=3):


return a + b + c
print(f(1, 2))
a) 3
b) 6
c) Error
d) None

25. Which built-in function returns the number of arguments a function takes?
a) args()
b) inspect()
c) code.co_argcount
d) parameters()

26. Output?

def f():
return
print(f())
a) None
b) 0
c) ""
d) Error

27. Which statement is true about Python functions?


a) Must have parameters
b) Must return a value
c) Can be without parameters and return value
d) Cannot be nested

28. Output?

def f(a, b):


return a ** b
print(f(2, 3))
a) 8
b) 6
c) 9
d) Error

29. Output?

x = 10
def f():
global x
x = 5
f()
print(x)
a) 5
b) 10
c) Error
d) None

30. Correct way to call fun with a=2, b=3?


a) fun(2, 3)
b) fun(a=2, b=3)
c) Both a and b
d) None

31. Output?

def f(*args):
return args
print(f(1,2))
a) (1, 2)
b) [1, 2]
c) 1, 2
d) Error

32. Output?

def f(**kwargs):
return kwargs
print(f(a=1, b=2))
a) {'a':1, 'b':2}
b) (1, 2)
c) [1, 2]
d) Error

33. Can a function have no parameters and no return value?


a) Yes
b) No
c) Only if empty
d) Only with pass

34. Output?

def f():
return "Hello", "World"
print(f())
a) Hello World
b) ("Hello", "World")
c) None
d) Error

35. Output?

def f(a, b=5, c=10):


print(a, b, c)
f(1, c=20)
a) 1 5 20
b) 1 20 5
c) 1 10 20
d) Error

36. Which statement is correct about lambda?


a) Multi-line
b) Single expression only
c) Cannot be assigned to variable
d) Can have statements

37. Output?

def f(a, b):


return a / b
print(f(5, 2))
a) 2.5
b) 2
c) Error
d) None

38. Output?

def f(a, b):


return a // b
print(f(5, 2))
a) 2.5
b) 2
c) Error
d) None

39. Can a function call itself in Python?


a) Yes
b) No
c) Only with def
d) Only with lambda
40. Output?

def fact(n):
if n == 0:
return 1
return n * fact(n-1)
print(fact(3))
a) 3
b) 6
c) 9
d) Error

41. Output?

def f(a, b):


print(a + b)
f(2, "3")
a) 5
b) 23
c) Error
d) None

42. Output?

def f(a, b):


print(str(a) + b)
f(2, "3")
a) 23
b) "23"
c) Error
d) None

43. Can functions be stored in lists?


a) Yes
b) No
c) Only with def
d) Only lambdas

44. Output?

square = lambda x: x**2


print(square(4))
a) 8
b) 16
c) 4
d) Error

45. Output?

def f(a, b):


return a is b
print(f(2, 2))
a) True
b) False
c) Error
d) None
46. Output?

def f(a, b):


return a == b
print(f([1,2], [1,2]))
a) True
b) False
c) Error
d) None

47. What is the scope of a variable declared inside a function?


a) Global
b) Local
c) Public
d) Static

48. Output?

def f(a=1, b=2):


return a + b
print(f(b=3))
a) 4
b) 3
c) 2
d) Error

49. Can functions be passed as arguments to other functions?


a) Yes
b) No
c) Only built-in functions
d) Only user-defined

50. Output?

def f():
return "Done"
g = f
print(g())
a) Done
b) f
c) g
d) Error

You might also like