You are on page 1of 34

Python Libraries

Salil Kumar Verma


Jawahar Navodaya Vidyalaya, Adilabad(T.S)
salilverma80@gmail.com

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 1/15


Outline

Python Library
Python Module
Importing Python module
Using Python Standard Library and Module
Mathematical and String Functions
Using random module

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 2/15


Library and Module

Library
refers to a collection of modules that together cater to
specific type of needs or applications

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 3/15


Library and Module

Library
refers to a collection of modules that together cater to
specific type of needs or applications

Module
A module is independent grouping of code and
data(variable, definitions, statements and
functions)

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 3/15


Library and Module

Library
refers to a collection of modules that together cater to
specific type of needs or applications

Module
A module is independent grouping of code and
data(variable, definitions, statements and
functions)
can be re-used in other programs

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 3/15


Library and Module

Library
refers to a collection of modules that together cater to
specific type of needs or applications

Module
A module is independent grouping of code and
data(variable, definitions, statements and
functions)
can be re-used in other programs
can depend on other modules

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 3/15


Python Libraries

Python standard library


This library is distributed with Python that contains
modules for various types of functionalities.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 4/15


Python Libraries

Python standard library


This library is distributed with Python that contains
modules for various types of functionalities.

NumPy
some advance math functionalities alongwith tools to
create and manipulate numeric arrays.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 4/15


Python Libraries

Python standard library


This library is distributed with Python that contains
modules for various types of functionalities.

NumPy
some advance math functionalities alongwith tools to
create and manipulate numeric arrays.

SciPy
offers algorithmic and mathematical tools for scientific
calculations.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 4/15


Python Library ..

tkinter
for creating userfriendly GUI interface.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 5/15


Python Library ..

tkinter
for creating userfriendly GUI interface.

matplotlib
plots, charts, graphs etc.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 5/15


Python Module

Python Module
is a file (.py file) containing variables, class definitions,
statements and functions related to a particular task.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 6/15


Python Standard Library

math
module
cmath
module
Python
urllib
Standard
module
Library
random
module
statistics
module

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 7/15


Importing Modules in Python

To import entire module:


To import a module e.g.
import time

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 8/15


Importing Modules in Python

To import entire module:


To import a module e.g.
import time
To import two modules viz. decimals and fractions
e.g.
import decimals,fractions

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 8/15


Importing Modules in Python

To import entire module:


To import a module e.g.
import time
To import two modules viz. decimals and fractions
e.g.
import decimals,fractions
dot notation: Consider a module tempConversion
contains a function to centigrade()
import tempConversion
tempConversion.to centigrade(98.6)

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 8/15


Importing Modules in Python

To import entire module:


To import a module e.g.
import time
To import two modules viz. decimals and fractions
e.g.
import decimals,fractions
dot notation: Consider a module tempConversion
contains a function to centigrade()
import tempConversion
tempConversion.to centigrade(98.6)
Using alias name:
import tempConversion as tc
tc.centigrade(98.6)

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 8/15


Importing Modules in Python ..

importing select objects from module


To import single object:
from math import pi print(math.pi)

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 9/15


Importing Modules in Python ..

importing select objects from module


To import single object:
from math import pi print(math.pi)
To import multiple objects:
from math import sqrt,pow

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 9/15


Importing Modules in Python ..

importing select objects from module


To import single object:
from math import pi print(math.pi)
To import multiple objects:
from math import sqrt,pow
To import all objects of a module:
from math import *

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 9/15


Python Standard Library Functions and Modules

Built-in Functions
need not import any module for them e.g. input(),
int(), float(), type(), len() etc.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 10/15


Python Standard Library Functions and Modules

Built-in Functions
need not import any module for them e.g. input(),
int(), float(), type(), len() etc.

oct()
returns octal
string for a given
number

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 10/15


Python Standard Library Functions and Modules

Built-in Functions
need not import any module for them e.g. input(),
int(), float(), type(), len() etc.

oct() hex()
returns octal returns hex string
string for a given for a given
number number

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 10/15


Python Standard Library Functions and Modules

Built-in Functions
need not import any module for them e.g. input(),
int(), float(), type(), len() etc.

oct() hex() bin()


returns octal returns hex string returns binary
string for a given for a given string for a given
number number number

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 10/15


Python Standard Library Functions and Modules

int()
truncates the fractional
part of given number

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 11/15


Python Standard Library Functions and Modules

int() round()
truncates the fractional returns number rounded to
part of given number n digits after decimal points

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 11/15


String functions

< str> .join()


If the string based iterator is a string then < str>
is inserted after every character of the string.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 12/15


String functions

< str> .join()


If the string based iterator is a string then < str>
is inserted after every character of the string.
If the string based iterator is a list or tuple of a
strings then, the given string/character is joined
with each member of the list or tuple, But the
tuple or list must have all member as strings.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 12/15


String functions..

< str> .split()


If you do not provide any argument to split then by
default it will split the given string considering
whitespace as a separator.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 13/15


String functions..

< str> .split()


If you do not provide any argument to split then by
default it will split the given string considering
whitespace as a separator.
If you provide a string or a character as an
argument to split(), then the given string is divided
into parts considering the given string/character as
separator and separator character is not included in
the split strings.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 13/15


String functions..

< str> .replace()


It replaces a string by a given string

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 14/15


random module

Using random Module


random module provides random-number generators.
To use random number generators in your Python
program, you first need to import module random using
import command.

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 15/15


random module

Using random Module


random module provides random-number generators.
To use random number generators in your Python
program, you first need to import module random using
import command.
random(): It returns floating point number N in
the range [0.0,1.0), i.e. 0.0 ≤ N < 1.0

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 15/15


random module

Using random Module


random module provides random-number generators.
To use random number generators in your Python
program, you first need to import module random using
import command.
random(): It returns floating point number N in
the range [0.0,1.0), i.e. 0.0 ≤ N < 1.0
randint(a,b): It returns a random integer N in
the range (a,b), i.e. a ≤ N ≤ b

Salil Kumar Verma, PGT IT, J N V Adilabad Functions 15/15

You might also like