Python Namespaces and Scope Quiz

Last Updated :
Discuss
Comments

Question 1

What is the purpose of the __call__ method in Python?

  • To call a function

  • To make an instance callable

  • To define class variables

  • To create a callable object

Question 2

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

  • To define a class property

  • To access global variables

  • To create a new property

  • To define a method as a property

Question 3

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

  • To define a static method in a class

  • To access global variables

  • To create a static variable

  • To declare a method as static

Question 4

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

  • Use the access keyword

  • Use the global keyword

  • Use the outer keyword

  • Use the variable name directly

Question 5

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

  • Returns a list of all global variables

  • Returns a list of all local variables

  • Returns a list of names in the current namespace

  • Returns a list of all functions in the current module

Question 6

What is the purpose of the threading module in Python?

  • To create threads and implement multithreading

  • To access global variables
     

  • To define class variables

  • To create thread-safe functions

Question 7

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

  • To define a partial function

  • To create a function with fixed arguments

  • To access global variables

  • To define a function with default arguments

Question 8

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

  • To call a method in the parent class

  • To create a superclass

  • To access global variables

  • To declare a variable as super

Question 9

What is the purpose of the __all__ attribute in Python?

  • To define all global variables

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

  • To list all local variables

  • To declare all class attributes

Question 10

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

  • It is executed when the program is imported as a module

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

  • It is used to define main functions

  • It is executed when a function is defined

There are 25 questions to complete.

Take a part in the ongoing discussion