Functions (User-defined & Built-in) Interview Questions

    Question 1Python Functions - Default Arguments

    What will be the output of the following code?

    def greet(name="Guest"): return f"Hello, {name}" print(greet())

    Question 2Python Functions - Built-in len()

    What does len("Python") return?

    Question 3Python Functions - Return Statement

    What will be the output?

    def add(a, b): return a + b print(add(2, 3) * 2)

    Question 4Python Functions - Keyword Arguments

    Which function call is valid for the following definition?

    def student(name, age): print(name, age)

    Question 5Python Functions - Scope of Variables

    What will be the output?

    x = 10 def test(): x = 20 print(x) test() print(x)

    Question 6Python Functions - Built-in max()

    What will max([3, 7, 2, 9, 5]) return?

    Question 7Python Functions - Anonymous Functions

    Which of the following correctly defines a lambda function to double a number?

    Question 8Python Functions - Built-in map()

    What will be the output?

    nums = [1, 2, 3] result = list(map(lambda x: x * 2, nums)) print(result)

    Question 9Python Functions - Recursive Function

    What will be the output?

    def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) print(factorial(3))

    Question 10Python Functions - *args Usage

    What will be the output?

    def add(*args): return sum(args) print(add(1, 2, 3, 4))