Page 244 - Computer Science Class 11 Without Functions
P. 244
10 MODULES
Chapter Outline
10.1 Built-in Modules
10.2 User-defined Modules
Introduction
In the chapter on Python Basics of Python Programming, we discussed several predefined built-in functions such
as input(), print(), int(), and abs(), dealing with input-output, data type conversion, and mathematical
operations. We also learnt to develop user-defined functions to perform some simple, useful tasks. However, Python
also provides specialised modules for specific tasks such as math and statistics, which provides several functions
for mathematical and statistical computations. Similarly, the random module provides several functions for random
number generation.
10.1 Built-in Modules
A Python module is just a Python script. Python provides several modules, each of which contains several useful
functions. Often, it is convenient to use predefined functions available in Python modules. However, to use these
functions, we need to import the relevant module using the following syntax:
import <modulename>
Once a module is imported, we can use all the functions defined in the module by preceding function name by the
name of the module and a dot(.) operator as shown below:
<modulename>.<functionname>()
For example, to use the sqrt() function defined in the math module, we first import the math module and then use
sqrt() function to find the square root of 25, as follows:
>>> import math
>>> math.sqrt(25)
5
A Python program file is called a Python module.
If you need any help regarding the functionality of a function or class in a module, you only need to invoke Python
built-in function, help() to display the documentation of the corresponding function or classe.
242 Touchpad Computer Science-XI

