Python Functions

Last Updated :
Discuss
Comments

Question 1

What is a function in Python?

  • A

    A keyword

  • B

    A type of variable

  • C

    An imported library

  • D

    A block of code that performs a specific task.


Question 2

Which of the following keyword is used to define a function in Python?

  • A

    func

  • B

    def

  • C

    class

  • D

    void

Question 3

What happens when a variable is defined inside a function and you attempt to access it from outside that function's body?

  • A

    The variable is accessed normally.

  • B

    The variable is stored in the global namespace.

  • C

    The value returns as 'None'.

  • D

    Python raises a NameError because the variable exists only in the local scope.

Question 4

Which specific keyword is required to modify a variable in the outer (enclosing) function from within an inner function?

  • A

    self

  • B

    global

  • C

    nonlocal

  • D

    static

Question 5

If a function is defined to return a value but does not include a return statement, what will be the result?

  • A

    The function will return a default value of 0

  • B

    The function will return an error

  • C

    The function will return None

  • D

    The function will return the last executed statement

Question 6

Which of the following statements about functions returning other functions is true?

  • A

    A function cannot return another function in Python

  • B

    The returned function can access variables from the outer function

  • C

    The returned function must be called immediately

  • D

    The outer function's execution must be completed before returning

Question 7

Which keyword is used in Python to create an anonymous function that can be defined in a single line without a name?

  • A

    anonymous

  • B

    inline

  • C

    lambda

  • D

    def

Question 8

Which type of argument uses a predefined value when no value is passed during a function call?

  • A

    Positional Argument

  • B

    Keyword Argument

  • C

    Default Argument

  • D

    Arbitrary Argument

Question 9

What is the primary difference between *args and **kwargs?

  • A

    *args handles keyword arguments, while **kwargs handles positional arguments.

  • B

    *args is used for recursion, while **kwargs is used for iteration.

  • C

    *args collects arguments into a list, while **kwargs collects them into a tuple.

  • D

    *args collects positional arguments into a tuple, while **kwargs collects keyword arguments into a dictionary.

Question 10

What is the output of the following program?

python
def update_val(x):
    x = x + 10

num = 5
update_val(num)
print(num)
  • A

    15

  • B

    None

  • C

    5

  • D

    Error: local variable referenced before assignment

There are 13 questions to complete.

Take a part in the ongoing discussion