SlideShare a Scribd company logo
5
Most read
13
Most read
18
Most read
Computer Science
Class XII
Python Libraries
1. Python Standard Library:
math module: for mathematical functions
cmath module:- mathematical functions for complex numbers.
random module :- functions for generating pseudo- random
numbers.
string module: for string/text-related functions.
USING PYTHON STANDARD LIBRARY’S FUNCTIONS AND MODULES
Python’s standard library is very extensive, offering a wide range of modules
and functions. The library contains built-in modules (written in C) that provide
access to system functionality such as file I/O, that would otherwise be
inaccessible to Python programmers, as well as modules written in Python
that provide standardized solutions for many problems that occur in everyday
programming. Some of these important modules are explicitly designed to
encourage and enhance the portability of Python programs.
2. NumPy Library- NumPy is the fundamental package for scientific
computing and manipulate numeric array with Python.
3. SciPy Library(pronounced ā€œSigh Pieā€) is a Python-based ecosystem
of open-source software for mathematics, science, and engineering.
4. Tkinter Library :Tkinter is actually an inbuilt Python module
used to create simple GUI apps. It is the most commonly used
module for GUI apps in the Python.
5. Matplotlib Library: Matplotlib is one of the most popular Python
packages used for data visualization. It is a cross-platform library
for making 2D plots from data in arrays.
Processing of import <module> command
1.Imported module’s code gets executed after interpretation.
2.All the programs and variables of imported module are present in the program.
Python import statement
import math
print(ā€œ2 to the power 3 is ", math.pow(2,3))
Import with renaming
import math as mt
print(ā€œ2 to the power 3 is ", mt.pow(2,3))
Processing of from <module> import <object> command
1.Imported module’s code gets executed after interpretation.
2.Only asked programs and variables of imported module are present in the program.
Python from...import statement
from math import pow
print(ā€œ2 to the power 3 is ", pow(2,3))
Import all names
from math import *
print(ā€œ2 to the power 3 is ", pow(2,3))
Python - Math Module
We have already discussed major functions using math module. Python
provides many other mathematical built-in functions as well. These include
trigonometric functions, representation functions, logarithmic functions, angle
conversion functions, etc. In addition, two mathematical constants are also
defined in this module.
Pie (Ļ€) is a well-known mathematical constant, which is defined as the ratio of the circumference
to the diameter of a circle and its value is 3.141592653589793.
import math
math.pi
3.141592653589793
from math import pi
print(pi)
3.141592653589793
or
Another well-known mathematical constant defined in the math module is e. It is called Euler's
number and it is a base of the natural logarithm. Its value is 2.718281828459045.
math.e
2.718281828459045
The math module presents two angle conversion functions: degrees() and radians()
, to convert the angle from degrees to radians and vice versa.
For example, the following statements convert the angle of 30 degrees to radians
and back.
math.radians(30)
0.5235987755982988
math.degrees(math.pi/6)
29.999999999999996
math.log()
The math.log() method returns the natural logarithm of a given number. The natural
logarithm is calculated to the base e.
math.log(10)
2.302585092994046
Python - Random Module
Functions in the random module depend on a pseudo-random number generator
function random(), which generates a random float number between 0.0 and 1.0.
random.random(): Generates a random float number between 0.0 to 1.0. The function doesn't
need any arguments.
import random
print(random.random())
random.randint(): Returns a random integer between the specified integers.
import random
print(random.randint(3, 9))
randrange() Method
import random
print(random.randrange(3, 90,2))
String Methods
Python has a set of built-in methods that you can use on strings.
Method Description
capitalize() Converts the first character to upper case
count() Returns the number of times a specified value occurs in a string
find() Searches the string for a specified value and returns the position of where it was
found
index() Searches the string for a specified value and returns the position of where it was
found
isalnum() Returns True if all characters in the string are alphanumeric
isalpha() Returns True if all characters in the string are in the alphabet
isdecimal() Returns True if all characters in the string are decimals
isdigit() Returns True if all characters in the string are digits
islower() Returns True if all characters in the string are lower case
isnumeric() Returns True if all characters in the string are numeric
isupper() Returns True if all characters in the string are upper case
lower() Converts a string into lower case
replace() Returns a string where a specified value is replaced with a specified value
split() Splits the string at the specified separator, and returns a list
Relation Between Python
Libraries, Module and
Package
•A module is a file containing
python definition, functions,
variables, classes and statements.
The extension of this file is ā€œ.pyā€.
•While Python package, is directory
(folder) of python modules.
•A library is collection of many
packages in python. Generally
there is no difference between
python package and python library.
Module in Python
•A module is a file containing python definition, functions, variables, classes and
statements. The extension of this file is ā€œ.pyā€.
Advantages–
–Its biggest advantage is that we can import its functionality in any program and
use it.
–Reusability is one of the biggest advantages.
–It helps in logically organization of Python code.
–Programming becomes very easy when we use the collection of same types of
codes.
–Categorization : same attributes can be stored in one module.
Python. libraries. modules. and. all.pdf
Python. libraries. modules. and. all.pdf
Namespaces in Python
•We imported a module in to a program which was referred as a namespace.
•To define a Namespace it is necessary to define its name.
•Python name is a kind of identifier which we use to access any python object. And in Python each and
everything is an object.
•Namespaces is used to separate the different sections of a program.
•Python has 3 types of namespaces -
–Global
–Local
–Built-in
Each module creates its own global namespace.
When we call a function then a local python namespace
is created where all the names of functions are exist.
Python. libraries. modules. and. all.pdf
Python. libraries. modules. and. all.pdf
PACKAGE / LIBRARY
•Python Package is the collection of same type of modules.
•You can use built in package as well as your own package.
•Python Package is a simple directory. Modules are stored in that directory.
•Package or library are generally same.
•Steps to make a package is as follows – (geometry)
1.We create a folder (directory) named geometry which will contain two files area.py
and volume.py
2.In the same directory we will put another file named ā€œ__init__.pyā€
3.__init__.py is necessary because this is the file which tells Python that directory is
package. And this file
initializes the package
4.Then we import the package and use the content.
Python. libraries. modules. and. all.pdf
Standard Python Libraries
We have already discussed about math and string module. Same way we will
discuss two more important libraries. - datetime library or datetime module.
Python supports yyyy-mm-dd format for date. It has tow important classes -
–date class
today ( )
year( )
month ( )
day ( )
–time class
now ( )
hour ( )
minute ( )
second ( )

More Related Content

PDF
Using Python Libraries.pdf
PPTX
Class 12 CBSE Chapter: python libraries.pptx
PDF
Python libraries
PDF
class 12 Libraries in dfbdsbsdbdfbdfdfdf.pdf
PPTX
Chapter 03 python libraries
PDF
Unit-2 Introduction of Modules and Packages.pdf
PDF
W-334535VBE242 Using Python Libraries.pdf
PDF
Python Modules, Packages and Libraries
Using Python Libraries.pdf
Class 12 CBSE Chapter: python libraries.pptx
Python libraries
class 12 Libraries in dfbdsbsdbdfbdfdfdf.pdf
Chapter 03 python libraries
Unit-2 Introduction of Modules and Packages.pdf
W-334535VBE242 Using Python Libraries.pdf
Python Modules, Packages and Libraries

Similar to Python. libraries. modules. and. all.pdf (20)

PPTX
Python Modules and Libraries
PPTX
Using python libraries.pptx , easy ppt to study class 12
PDF
ch 2. Python module
PPTX
An Introduction : Python
PPTX
Python for Beginners
PPTX
Using-Python-Libraries.9485146.powerpoint.pptx
PDF
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
PDF
Modules and Packages in Python_Basics.pdf
PPSX
Modules and packages in python
PPTX
Modules and Packages in Python Programming Language.pptx
DOCX
Modules in Python.docx
PDF
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
PPTX
package module in the python environement.pptx
PPTX
packages.pptx
PPT
Pythonintroduction
PDF
Python lec1
PPTX
Introduction to Python programming Language
PDF
Intro-to-Python-Part-1-first-part-edition.pdf
PPTX
Python module 3, b.tech 5th semester ppt
PPTX
Introduction on basic python and it's application
Python Modules and Libraries
Using python libraries.pptx , easy ppt to study class 12
ch 2. Python module
An Introduction : Python
Python for Beginners
Using-Python-Libraries.9485146.powerpoint.pptx
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Modules and Packages in Python_Basics.pdf
Modules and packages in python
Modules and Packages in Python Programming Language.pptx
Modules in Python.docx
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
package module in the python environement.pptx
packages.pptx
Pythonintroduction
Python lec1
Introduction to Python programming Language
Intro-to-Python-Part-1-first-part-edition.pdf
Python module 3, b.tech 5th semester ppt
Introduction on basic python and it's application
Ad

Recently uploaded (20)

PPTX
Type of Sentence & SaaaaaaaaaadddVA.pptx
PDF
Volvo ecr145cl specs Service Manual Download
PDF
How much does a e145 excavator weight.pdf
PDF
3-REasdfghjkl;[poiunvnvncncn-Process.pdf
PPTX
Paediatric History & Clinical Examination.pptx
PDF
120725175041.pdfhjjjjjjjjjjjjjjjjjjjjjjh
PPT
ACCOMPLISHMENT REPOERTS AND FILE OF GRADE 12 2021.ppt
PDF
Honda Dealership SNS Evaluation pdf/ppts
PDF
How Much does a Volvo EC290C NL EC290CNL Weight.pdf
PDF
Caterpillar Cat 329D LN Excavator (Prefix EBM) Service Repair Manual Instant ...
PDF
EC300D LR EC300DLR - Volvo Service Repair Manual.pdf
PPTX
vsdfhlahsadfjkhasihdflakjsdfhlajdhlfkjahfdljkash
PDF
Volvo ecr88 lifting capacity Service Repair Manual.pdf
PDF
Volvo EC290C NL EC290CNL excavator weight.pdf
PDF
Physics class 12thstep down transformer project.pdf
PDF
Volvo ecr58 plus Service Manual Download
PDF
higher edu open stores 12.5.24 (1).pdf forreal
Ā 
PDF
Volvo ecr88 excavator specs Manual Download
PDF
Caterpillar CAT 312B L EXCAVATOR (2KW00001-UP) Operation and Maintenance Manu...
PDF
Delivers.ai: 2020–2026 Autonomous Journey
Type of Sentence & SaaaaaaaaaadddVA.pptx
Volvo ecr145cl specs Service Manual Download
How much does a e145 excavator weight.pdf
3-REasdfghjkl;[poiunvnvncncn-Process.pdf
Paediatric History & Clinical Examination.pptx
120725175041.pdfhjjjjjjjjjjjjjjjjjjjjjjh
ACCOMPLISHMENT REPOERTS AND FILE OF GRADE 12 2021.ppt
Honda Dealership SNS Evaluation pdf/ppts
How Much does a Volvo EC290C NL EC290CNL Weight.pdf
Caterpillar Cat 329D LN Excavator (Prefix EBM) Service Repair Manual Instant ...
EC300D LR EC300DLR - Volvo Service Repair Manual.pdf
vsdfhlahsadfjkhasihdflakjsdfhlajdhlfkjahfdljkash
Volvo ecr88 lifting capacity Service Repair Manual.pdf
Volvo EC290C NL EC290CNL excavator weight.pdf
Physics class 12thstep down transformer project.pdf
Volvo ecr58 plus Service Manual Download
higher edu open stores 12.5.24 (1).pdf forreal
Ā 
Volvo ecr88 excavator specs Manual Download
Caterpillar CAT 312B L EXCAVATOR (2KW00001-UP) Operation and Maintenance Manu...
Delivers.ai: 2020–2026 Autonomous Journey
Ad

Python. libraries. modules. and. all.pdf

  • 2. 1. Python Standard Library: math module: for mathematical functions cmath module:- mathematical functions for complex numbers. random module :- functions for generating pseudo- random numbers. string module: for string/text-related functions. USING PYTHON STANDARD LIBRARY’S FUNCTIONS AND MODULES Python’s standard library is very extensive, offering a wide range of modules and functions. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O, that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming. Some of these important modules are explicitly designed to encourage and enhance the portability of Python programs.
  • 3. 2. NumPy Library- NumPy is the fundamental package for scientific computing and manipulate numeric array with Python. 3. SciPy Library(pronounced ā€œSigh Pieā€) is a Python-based ecosystem of open-source software for mathematics, science, and engineering. 4. Tkinter Library :Tkinter is actually an inbuilt Python module used to create simple GUI apps. It is the most commonly used module for GUI apps in the Python. 5. Matplotlib Library: Matplotlib is one of the most popular Python packages used for data visualization. It is a cross-platform library for making 2D plots from data in arrays.
  • 4. Processing of import <module> command 1.Imported module’s code gets executed after interpretation. 2.All the programs and variables of imported module are present in the program. Python import statement import math print(ā€œ2 to the power 3 is ", math.pow(2,3)) Import with renaming import math as mt print(ā€œ2 to the power 3 is ", mt.pow(2,3)) Processing of from <module> import <object> command 1.Imported module’s code gets executed after interpretation. 2.Only asked programs and variables of imported module are present in the program. Python from...import statement from math import pow print(ā€œ2 to the power 3 is ", pow(2,3)) Import all names from math import * print(ā€œ2 to the power 3 is ", pow(2,3))
  • 5. Python - Math Module We have already discussed major functions using math module. Python provides many other mathematical built-in functions as well. These include trigonometric functions, representation functions, logarithmic functions, angle conversion functions, etc. In addition, two mathematical constants are also defined in this module. Pie (Ļ€) is a well-known mathematical constant, which is defined as the ratio of the circumference to the diameter of a circle and its value is 3.141592653589793. import math math.pi 3.141592653589793 from math import pi print(pi) 3.141592653589793 or Another well-known mathematical constant defined in the math module is e. It is called Euler's number and it is a base of the natural logarithm. Its value is 2.718281828459045. math.e 2.718281828459045
  • 6. The math module presents two angle conversion functions: degrees() and radians() , to convert the angle from degrees to radians and vice versa. For example, the following statements convert the angle of 30 degrees to radians and back. math.radians(30) 0.5235987755982988 math.degrees(math.pi/6) 29.999999999999996 math.log() The math.log() method returns the natural logarithm of a given number. The natural logarithm is calculated to the base e. math.log(10) 2.302585092994046
  • 7. Python - Random Module Functions in the random module depend on a pseudo-random number generator function random(), which generates a random float number between 0.0 and 1.0. random.random(): Generates a random float number between 0.0 to 1.0. The function doesn't need any arguments. import random print(random.random()) random.randint(): Returns a random integer between the specified integers. import random print(random.randint(3, 9)) randrange() Method import random print(random.randrange(3, 90,2))
  • 8. String Methods Python has a set of built-in methods that you can use on strings. Method Description capitalize() Converts the first character to upper case count() Returns the number of times a specified value occurs in a string find() Searches the string for a specified value and returns the position of where it was found index() Searches the string for a specified value and returns the position of where it was found isalnum() Returns True if all characters in the string are alphanumeric isalpha() Returns True if all characters in the string are in the alphabet isdecimal() Returns True if all characters in the string are decimals isdigit() Returns True if all characters in the string are digits islower() Returns True if all characters in the string are lower case isnumeric() Returns True if all characters in the string are numeric isupper() Returns True if all characters in the string are upper case lower() Converts a string into lower case replace() Returns a string where a specified value is replaced with a specified value split() Splits the string at the specified separator, and returns a list
  • 9. Relation Between Python Libraries, Module and Package •A module is a file containing python definition, functions, variables, classes and statements. The extension of this file is ā€œ.pyā€. •While Python package, is directory (folder) of python modules. •A library is collection of many packages in python. Generally there is no difference between python package and python library.
  • 10. Module in Python •A module is a file containing python definition, functions, variables, classes and statements. The extension of this file is ā€œ.pyā€. Advantages– –Its biggest advantage is that we can import its functionality in any program and use it. –Reusability is one of the biggest advantages. –It helps in logically organization of Python code. –Programming becomes very easy when we use the collection of same types of codes. –Categorization : same attributes can be stored in one module.
  • 13. Namespaces in Python •We imported a module in to a program which was referred as a namespace. •To define a Namespace it is necessary to define its name. •Python name is a kind of identifier which we use to access any python object. And in Python each and everything is an object. •Namespaces is used to separate the different sections of a program. •Python has 3 types of namespaces - –Global –Local –Built-in Each module creates its own global namespace. When we call a function then a local python namespace is created where all the names of functions are exist.
  • 16. PACKAGE / LIBRARY •Python Package is the collection of same type of modules. •You can use built in package as well as your own package. •Python Package is a simple directory. Modules are stored in that directory. •Package or library are generally same. •Steps to make a package is as follows – (geometry) 1.We create a folder (directory) named geometry which will contain two files area.py and volume.py 2.In the same directory we will put another file named ā€œ__init__.pyā€ 3.__init__.py is necessary because this is the file which tells Python that directory is package. And this file initializes the package 4.Then we import the package and use the content.
  • 18. Standard Python Libraries We have already discussed about math and string module. Same way we will discuss two more important libraries. - datetime library or datetime module. Python supports yyyy-mm-dd format for date. It has tow important classes - –date class today ( ) year( ) month ( ) day ( ) –time class now ( ) hour ( ) minute ( ) second ( )