Python Namespaces and Scope Quiz

Last Updated :
Discuss
Comments

Question 1

What is the purpose of the __call__ method in Python?

  • A

    To call a function

  • B

    To make an instance callable

  • C

    To define class variables

  • D

    To create a callable object

Question 2

In Python, what is the purpose of the property() function?

  • A

    To define a class property

  • B

    To access global variables

  • C

    To create a new property

  • D

    To define a method as a property

Question 3

What is the purpose of the 'staticmethod' decorator in Python?

  • A

    To define a static method in a class

  • B

    To access global variables

  • C

    To create a static variable

  • D

    To declare a method as static

Question 4

How can you access a global variable from within a function in Python?

  • A

    Use the access keyword

  • B

    Use the global keyword

  • C

    Use the outer keyword

  • D

    Use the variable name directly

Question 5

What is the purpose of the dir() function in Python?

  • A

    Returns a list of all global variables

  • B

    Returns a list of all local variables

  • C

    Returns a list of names in the current namespace

  • D

    Returns a list of all functions in the current module

Question 6

What is the purpose of the threading module in Python?

  • A

    To create threads and implement multithreading

  • B

    To access global variables
     

  • C

    To define class variables

  • D

    To create thread-safe functions

Question 7

What is the purpose of the functools.partial function in Python?

  • A

    To define a partial function

  • B

    To create a function with fixed arguments

  • C

    To access global variables

  • D

    To define a function with default arguments

Question 8

In Python, what is the purpose of the super() function?

  • A

    To call a method in the parent class

  • B

    To create a superclass

  • C

    To access global variables

  • D

    To declare a variable as super

Question 9

What is the purpose of the __all__ attribute in Python?

  • A

    To define all global variables

  • B

    To specify which names should be imported when using from module import *

  • C

    To list all local variables

  • D

    To declare all class attributes

Question 10

Which of the following is true regarding the __main__ block in Python?

  • A

    It is executed when the program is imported as a module

  • B

     It is executed when the program is run as the main program

  • C

    It is used to define main functions

  • D

    It is executed when a function is defined

There are 25 questions to complete.

Take a part in the ongoing discussion