Module Built-in Functions:
(1) dir ( ) built-in function:
the dir( ) function is used to find out names(i.e function, variable, class) that are defined
inside a module.
The following code shows the use of dir ( ) function in the module.
[Link]
def add(a,b):
result = a+b
return result
[Link]
import example
print(dir(example))
output:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__',
'__spec__', 'add']
Here, we can see a sorted list of names (along with add). All other names that begin with an
underscore are default python attributes associated with the module (not user-defined).
(2) OS Module:
import os
Method Example Description
name [Link] gives the name of the
operating system
getcwd( ) [Link]( ) This function returns the
current working
directory.
mkdir( ) [Link](“python”) Creates a directory with
the python name.
rename(oldname,newname) [Link](“python”,“pspp”) Rename the directory
remove( ) [Link](“pspp”) Remove (delete)the
directory
or folder
getuid( ) [Link]() Return the current
process’s user id
environ [Link] Get the users
environment
chdir( ) [Link]( ) Change the working
directory
chroot( ) [Link]( ) Change root directory
of current process.
(3) SYS Module:
import sys
Method Example Description
[Link] [Link] Provides the list of command
line arguments passed to a
python script.
[Link](0) Provides to access the file name
[Link](1) Provides to access the first input
[Link] [Link] It provide the search path for
module
[Link]() [Link]() Provide the access to specific
path to our program
[Link] [Link] Provide information about the
operating system platform
[Link] [Link] Exit from python program.
[Link] [Link] Provides the current version
number of the python
interpreter.
[Link] [Link] Returns the largest integer a
variable can take.
(4) Math Module:
(5) Statistics Module:
import statistics
Method Example Description
mean() [Link]([2,5,6,9]) calculates the arithmetic
5.5 mean of the numbers in
a list.
median() [Link]([1,2,3,8,9]) returns the middle value
3 of numeric data in a list.
[Link]([1,2,3,7,8,9])
5.0
mode() [Link]([2,5,3,2,8,3,9,4,2,5,6]) returns the most
2 common data point in
the list.
stdev() [Link]([1,1.5,2,2.5,3,3.5,4,4.5 calculates the standard
,5]) deviation on a given
1.3693063937629153 sample in the form of a
list.
(6) Random Module
import random
Method Example Description
[Link]() [Link]() returns a random float number
between 0.0 to 1.0.
[Link]() [Link](1, 100) returns a random integer
95 between the specified integers.
[Link](1, 100)
49
[Link]( [Link](1, 10) returns a randomly selected
) 2 element from the range created
[Link](1, 10, 2) by the start, stop and step
5 arguments.
[Link](0, 101, 10)
80
[Link]() [Link]('computer') returns a randomly selected
't' element from a non-empty
[Link]([12,23,45,67,65,43 sequence.
]) An empty sequence as argument
45 raises an Index Error.
[Link]((12,23,45,67,65,43
))
67
[Link]() numbers=[12,23,45,67,65,43] randomly reorders the elements
[Link](numbers) in a list.
numbers
[23, 12, 43, 65, 67, 45]