wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Programming in Python - Unit III

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is a module in Python?

a)

A built-in Python function

b)

A collection of related classes and functions

c)

A way to import external libraries

d)

A file containing Python code that can be imported and used

2.

Which module provides mathematical functions and constants in Python?

a)

math

b)

random

c)

os

d)

sys

3.

How do you import a module named my_module in Python?

a)

import my_module

b)

import module.my_module

c)

from my_module import *

d)

import my_module as mm

4.

What does the sys.path variable represent in Python?

     

a)

The path of the Python interpreter

b)

The current working directory

c)

The list of directories Python searches for modules

d)

The path to the Python standard library

5.

What is a namespace in Python?

a)

A region where a variable is stored

b)

A keyword used for defining classes

c)

A unique identifier for a variable

d)

A container for holding variables and functions

6.

What does the dir() function do in Python?

a)

Lists all available modules in Python

b)

Returns the names in the current local scope or a module's attributes

c)

Lists all built-in functions in Python

d)

Checks if a variable is defined in the local scope

7.

Which module should be imported to use the reload() function in Python 3.x?

a)

reload

b)

importlib

c)

imp

d)

sys

8.

What is a package in Python?

a)

A single Python file

b)

A collection of related modules

c)

A built-in Python module

d)

A way to install external libraries

9.

Which module provides date and time functionalities in Python?

     

a)

time

b)

datetime

c)

calendar

d)

date

10.

How do you open a file named "example.txt" in read mode in Python?

      

a)

file = open("example.txt", "r")

b)

file = open("example.txt", mode="r")

c)

file = open("example.txt", read=True)

d)

file = open("example.txt", mode="read")

11.

How do you check if a directory exists in Python?

a)

Use the exists() function from the os module

b)

Use the isdir() function from the os.path module

c)

Use the dir_exists() function from the os module

d)

Use the exists() function from the os.path module

12.

 What is the purpose of a package in Python?

a)

To organize modules and provide a hierarchical structure

b)

To import external libraries

c)

To create a single Python file

d)

To define built-in functions

13.

Which module is used for interacting with the operating system in Python?

a)

os

b)

sys

c)

math

d)

datetime

14.

What is the difference between global and local scope in Python?

a)

Global scope refers to variables defined within a function, while local scope refers to variables defined outside any function.

b)

Global scope refers to variables defined outside any function, while local scope refers to variables defined within a function.

c)

Global scope refers to variables defined within a module, while local scope refers to variables defined within a class.

d)

Global scope refers to variables defined within a class, while local scope refers to variables defined within a module.

15.

How do you close a file in Python after reading or writing?

a)

file.close()

b)

close(file)

c)

file.exit()

d)

exit(file)

16.

What is the difference between a module and a package in Python?

     

a)

A module is a single Python file, while a package is a collection of modules.

b)

A module contains functions, while a package contains classes.

c)

A module is used for file handling, while a package is used for mathematical operations.

d)

A module is created by the user, while a package is provided by Python's standard library.

17.

Which module provides functionalities for working with regular expressions in Python?

a)

re

b)

os

c)

sys

d)

math

18.

How do you create a module in Python?

a)

By saving a Python script with a .mod extension

b)

By creating a directory with the module name and placing Python scripts inside it

c)

By defining a class and using it as a module

d)

By importing a built-in module and modifying it

19.

What is the purpose of the PYTHONPATH environment variable in Python?

a)

It defines the location of the Python interpreter on the system.

b)

It specifies the default directory for storing Python scripts.

c)

It sets the search path for modules when importing.

d)

It determines the file extension for Python modules.

20.

What is the scope of a variable defined inside a function in Python?

a)

Local scope

b)

Global scope

c)

Class scope

d)

Built-in scope

21.

Which of the following statements is true about the dir() function in Python?

a)

It lists all available modules in Python.

b)

It lists all built-in functions and variables in Python.

c)

It returns a sorted list of attributes of an object or a module.

d)

It displays the current working directory.

22.

Which module should be imported to use the reload() function in Python 2.x?

a)

reload

b)

importlib

c)

imp

d)

sys

23.

How are modules organized within a package in Python?

a)

By placing them in a directory with the package name and importing them.

b)

By defining them as classes and using them as packages.

c)

By including them in a separate file with the package name.

d)

By saving them as individual scripts in the package directory.

24.

Which module provides functionalities for formatting dates and times in Python?

a)

datetime

b)

time

c)

calendar

d)

date

25.

What is the purpose of the with statement in file handling in Python?

a)

It opens a file in write mode.

b)

It automatically closes the file after reading or writing.

c)

It reads the entire file content at once.

d)

It provides an interface for interacting with the operating system.

26.

Which module is used for interacting with directories in Python?

      

a)

os

b)

sys

c)

shutil

d)

pathlib

27.

How do you import a module named my_module in Python using the from statement?

a)

from my_module import module

b)

from my_module import my_module

c)

from my_module import *

d)

from my_module import function

28.

Which module is used for working with command-line arguments in Python?

      

a)

argparse

b)

sys

c)

os

d)

math

29.

What happens if you try to access a variable defined inside a function outside its scope?

a)

It will raise an error.

b)

It will be accessible and have the same value as inside the function.

c)

It will be accessible but have a different value than inside the function.

d)

It will only be accessible in the global scope.

30.

Which method is used to check if a directory exists in Python?

a)

os.path.exists()

b)

os.path.isfile()

c)

os.path.isdir()

d)

os.path.getsize()