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.
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
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.
#Returns the reversed String.
# str1 (str):The string which is to be reversed.
# reverse(str1):The string which gets reversed.
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.
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 folder2. 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.
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.
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.
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.
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.
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.
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.
(i) numpy(ii) math
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
Because it imports the <module> and create the reference to all the members of the <onkect>.
Standard library of Python is official script of the documentation and program used to simplify the programming process and interpreting the access.
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 TutorIn 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