[Type A] Chapter – 4 Class 12 CS – Sumita Arora Assignment | Q/A

Here is class 12 computer science Unit 4 [Type A] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 4 and for all chapters here.

Watch all tutorials for chapter 4: Python Revision Tour.

Q1: What is the significance of the Modules?

Module contains some complex code that can used and called by importing that module to have an easy access and save time and error to reinitiate the same purpose again.

For example : we want to apply Permutation logic then to code the logic we can simply import the logic in direct use.

from itertools import permutations
Q2: What are docstrings? What is its significance? Give example to support your answer.

Python documentation string (docstring) is the reference documentation attached with source code of module, function, class and objects in python. It is accessible with (__doc__) attribute and (help()) for built-in modules.

It is highly recommended as it help anyone to use the module to understand the module by docstring and apply in accordance to that.

def string_reverse(str1): 
    #Returns the reversed String. 
    #Parameters: 
    # str1 (str):The string which is to be    reversed. 
   #Returns: 
   # reverse(str1):The string which gets reversed.     
Q3: What is a package? How is a package different from the module?

A package is the collection of various modules in single entity along with a __init__.py to leverage the structure of package.

A module is a single .py file that having some functioning program.

Q4: What is a library? Write a procedure to create own library in Python.

Library is the collection of functions and methods that allow to perform many tasks without coding for that.
For example : OpenCV is a library that allow to perform many task on video and image processing.

Procedure to create own library:
1. Create a folder
2. Under this folder create subfolder with the name of packages.
3. Fill these packages with the module and the __init__.py.
4. Full fill the structure and library is ready.

Q5: What is the use of file __init__.py in a package even when it is empty?

Any directory containing many module (.py) with presence of __init__.py being treated as package by python. Hence, its presence even if empty just make a meaning to it.

Q6: What is the importance of the site-packages folder of Python installation?

site_package is the by default folder structure that created when we install or download a python package (modules directory) from external source using install setup into local system.

Q7: How are the following import statements different?
(a) import X
(b) from X import *
(c) from X import a, b, c

In import X, the whole module X get imported in main active working space, and we can use any sub function. Such as add function in X as X.add(4, 5).
In from X import* we can directly use any sub function such as add in above case directly as add(4, 5). It loads the whole module in active working space and hence this method is not recommanded.
In from X import a, b, c only specific sub-section such as a, b, c get imported rather than complete section as in above cases.

Q8: What is PYTHON PATH variable? What is its significance?

PYTHONPATH is an environment variable that is global setup of the python executable extension file that is needed when coding and executing in python IDLE. By PYTHONPATH python came to know where to find its whole setup files.

Q9: In which order Python looks for the function/module names used by you.

The python always first look in the built-in module for the functions/module and if not found then it looks into the list of the PYTHONPATH variable for the name.

Q10: What is the usage of help() and dir() function?

help() return the documentation or docstrings of passed argument (function/ module) to command for reference.
>>> help(numpy)

dir() will pass the list of valid attribute of the entered attribute and in absence of attribute it pass the attribute list for local scope.

Q11: Name the Python Library modules which need to be imported to involve the following functions:
(i) log()
(ii) pow()

(i) numpy
(ii) math

Q12: What is the dot notation of referring to objects inside a module?

The dot notation is used to refer the function, class, object … inside the .py file to implement.

# inside swap_value.py module
def swap(a, b):
    ....

# main coding section
import swap_value.py
swap_value.swap(5, 4)

Q13: Why should the from <module> import <onkect> statement be avoided to import objects?

Because it imports the <module> and create the reference to all the members of the <onkect>.

Q14: What do you understand by the standard library of Python?

Standard library of Python is official script of the documentation and program used to simplify the programming process and interpreting the access.

Q15: Explain the difference between import <module> and from <module>import statements, with examples.

import <module>
just import the module and create the reference to all the modules in it in current namespace, and to use any sub-module we need to mention full path.
Example : import math
math.add(4,5)

from <module> import <sub>
import the module and create a reference to the sub and part of it. No further addressing is needed, and we are limited to sub under module but not in above case.
Example : from math import add
add(4,5)

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in

You cannot copy content of this page