SlideShare a Scribd company logo
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.
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.
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.
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

Similar to Python. libraries. modules. and. all.pdf

pythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docxpythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docx
RameshMishra84
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
arvdexamsection
 
Python training
Python trainingPython training
Python training
Kunalchauhan76
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
Singamvineela
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
DrRShaliniVISTAS
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
Shubham Yadav
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
kavinilavuG
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya
 
Python
PythonPython
Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and Modules
RaginiJain21
 
Python with data Sciences
Python with data SciencesPython with data Sciences
Python with data Sciences
Krishna Mohan Mishra
 
Chapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer ScienceChapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer Science
KrithikaTM
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
SURBHI SAROHA
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
Karthik Prakash
 
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxPython-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
anushya2915
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
zynofustechnology
 
Functions2.pptx
Functions2.pptxFunctions2.pptx
Functions2.pptx
AkhilTyagi42
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
alaparthi
 
cbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptxcbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptx
tcsonline1222
 

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

pythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docxpythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docx
 
Functions-.pdf
Functions-.pdfFunctions-.pdf
Functions-.pdf
 
Python training
Python trainingPython training
Python training
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 
summer training report on python
summer training report on pythonsummer training report on python
summer training report on python
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python
PythonPython
Python
 
Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and Modules
 
Python with data Sciences
Python with data SciencesPython with data Sciences
Python with data Sciences
 
Chapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer ScienceChapter Functions for grade 12 computer Science
Chapter Functions for grade 12 computer Science
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptxPython-Libraries,Numpy,Pandas,Matplotlib.pptx
Python-Libraries,Numpy,Pandas,Matplotlib.pptx
 
Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
Functions2.pptx
Functions2.pptxFunctions2.pptx
Functions2.pptx
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
 
cbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptxcbse class 12 Python Functions2 for class 12 .pptx
cbse class 12 Python Functions2 for class 12 .pptx
 

Recently uploaded

Here's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDsHere's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDs
jennifermiller8137
 
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
78tq3hi2
 
MODULE ONE PRPC19 Design of Machine Elements- 1 .pdf
MODULE  ONE PRPC19 Design of Machine Elements- 1 .pdfMODULE  ONE PRPC19 Design of Machine Elements- 1 .pdf
MODULE ONE PRPC19 Design of Machine Elements- 1 .pdf
ShanthiniSellamuthu
 
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitExpanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Forth
 
Catalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptxCatalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptx
Blue Star Brothers
 
RACI Matrix Managed Services on Cloud 08-11-19_AS.pdf
RACI Matrix Managed Services on Cloud 08-11-19_AS.pdfRACI Matrix Managed Services on Cloud 08-11-19_AS.pdf
RACI Matrix Managed Services on Cloud 08-11-19_AS.pdf
xmasmen4u
 
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
78tq3hi2
 
EN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptxEN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptx
aichamardi99
 
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
MarynaYurchenko2
 
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
afkxen
 
EV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin DonnellyEV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin Donnelly
Forth
 
原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样
原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样
原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样
g1inbfro
 
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
afkxen
 
Charging Fueling & Infrastructure (CFI) Program Resources by Cat Plein
Charging Fueling & Infrastructure (CFI) Program Resources by Cat PleinCharging Fueling & Infrastructure (CFI) Program Resources by Cat Plein
Charging Fueling & Infrastructure (CFI) Program Resources by Cat Plein
Forth
 
EV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker JamiesonEV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker Jamieson
Forth
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects
 
Hand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptxHand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptx
wstatus456
 
Kaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality EngineerspptxKaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality Engineerspptx
vaibhavsrivastava482521
 
Charging and Fueling Infrastructure Grant: Round 2 by Brandt Hertenstein
Charging and Fueling Infrastructure Grant: Round 2 by Brandt HertensteinCharging and Fueling Infrastructure Grant: Round 2 by Brandt Hertenstein
Charging and Fueling Infrastructure Grant: Round 2 by Brandt Hertenstein
Forth
 
Charging Fueling & Infrastructure (CFI) Program by Kevin Miller
Charging Fueling & Infrastructure (CFI) Program  by Kevin MillerCharging Fueling & Infrastructure (CFI) Program  by Kevin Miller
Charging Fueling & Infrastructure (CFI) Program by Kevin Miller
Forth
 

Recently uploaded (20)

Here's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDsHere's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDs
 
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
 
MODULE ONE PRPC19 Design of Machine Elements- 1 .pdf
MODULE  ONE PRPC19 Design of Machine Elements- 1 .pdfMODULE  ONE PRPC19 Design of Machine Elements- 1 .pdf
MODULE ONE PRPC19 Design of Machine Elements- 1 .pdf
 
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitExpanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
 
Catalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptxCatalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptx
 
RACI Matrix Managed Services on Cloud 08-11-19_AS.pdf
RACI Matrix Managed Services on Cloud 08-11-19_AS.pdfRACI Matrix Managed Services on Cloud 08-11-19_AS.pdf
RACI Matrix Managed Services on Cloud 08-11-19_AS.pdf
 
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
 
EN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptxEN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptx
 
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
 
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
 
EV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin DonnellyEV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin Donnelly
 
原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样
原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样
原版制作(澳洲WSU毕业证书)西悉尼大学毕业证文凭证书一模一样
 
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
 
Charging Fueling & Infrastructure (CFI) Program Resources by Cat Plein
Charging Fueling & Infrastructure (CFI) Program Resources by Cat PleinCharging Fueling & Infrastructure (CFI) Program Resources by Cat Plein
Charging Fueling & Infrastructure (CFI) Program Resources by Cat Plein
 
EV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker JamiesonEV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker Jamieson
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
 
Hand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptxHand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptx
 
Kaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality EngineerspptxKaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality Engineerspptx
 
Charging and Fueling Infrastructure Grant: Round 2 by Brandt Hertenstein
Charging and Fueling Infrastructure Grant: Round 2 by Brandt HertensteinCharging and Fueling Infrastructure Grant: Round 2 by Brandt Hertenstein
Charging and Fueling Infrastructure Grant: Round 2 by Brandt Hertenstein
 
Charging Fueling & Infrastructure (CFI) Program by Kevin Miller
Charging Fueling & Infrastructure (CFI) Program  by Kevin MillerCharging Fueling & Infrastructure (CFI) Program  by Kevin Miller
Charging Fueling & Infrastructure (CFI) Program by Kevin Miller
 

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.
  • 11.
  • 12.
  • 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.
  • 14.
  • 15.
  • 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.
  • 17.
  • 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 ( )