際際滷

際際滷Share a Scribd company logo
3
Most read
10
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 LIBRARYS FUNCTIONS AND MODULES
Pythons 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 鍖le 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 scienti鍖c
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 modules 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 modules 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
de鍖ned in this module.
Pie () is a well-known mathematical constant, which is de鍖ned 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 de鍖ned 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 鍖oat number between 0.0 and 1.0.
random.random(): Generates a random 鍖oat 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 speci鍖ed 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 鍖rst character to upper case
count() Returns the number of times a speci鍖ed value occurs in a string
鍖nd() Searches the string for a speci鍖ed value and returns the position of where it was
found
index() Searches the string for a speci鍖ed 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 speci鍖ed value is replaced with a speci鍖ed value
split() Splits the string at the speci鍖ed separator, and returns a list
Relation Between Python
Libraries, Module and
Package
A module is a 鍖le containing
python de鍖nition, functions,
variables, classes and statements.
The extension of this 鍖le 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 鍖le containing python de鍖nition, functions, variables, classes and
statements. The extension of this 鍖le 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 de鍖ne a Namespace it is necessary to de鍖ne its name.
Python name is a kind of identi鍖er 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 鍖les area.py
and volume.py
2.In the same directory we will put another 鍖le named __init__.py
3.__init__.py is necessary because this is the 鍖le which tells Python that directory is
package. And this 鍖le
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 ( )
Ad

Recommended

Using Python Libraries.pdf
Using Python Libraries.pdf
SoumyadityaDey
Class 12 CBSE Chapter: python libraries.pptx
Class 12 CBSE Chapter: python libraries.pptx
AravindVaithianadhan
Python libraries
Python libraries
Prof. Dr. K. Adisesha
Chapter 03 python libraries
Chapter 03 python libraries
Praveen M Jigajinni
W-334535VBE242 Using Python Libraries.pdf
W-334535VBE242 Using Python Libraries.pdf
manassingh1509
Python Modules, Packages and Libraries
Python Modules, Packages and Libraries
Venugopalavarma Raja
Python Modules and Libraries
Python Modules and Libraries
Venugopalavarma Raja
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
anikedheikhamsingh
ch 2. Python module
ch 2. Python module
Prof .Pragati Khade
An Introduction : Python
An Introduction : Python
Raghu Kumar
Python for Beginners
Python for Beginners
DrRShaliniVISTAS
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
UadAccount
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
Modules and packages in python
Modules and packages in python
TMARAGATHAM
Modules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
Modules in Python.docx
Modules in Python.docx
manohar25689
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
rajkumar2792005
package module in the python environement.pptx
package module in the python environement.pptx
MuhammadAbdullah311866
packages.pptx
packages.pptx
SHAIKIRFAN715544
Pythonintroduction
Pythonintroduction
-jyothish kumar sirigidi
Python lec1
Python lec1
Swarup Ghosh
Introduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3
Intro-to-Python-Part-1-first-part-edition.pdf
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
Python module 3, b.tech 5th semester ppt
Python module 3, b.tech 5th semester ppt
course5325
Introduction on basic python and it's application
Introduction on basic python and it's application
sriram2110
Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12
JAYASURYANSHUPEDDAPA
CLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
New Holland Lx465 Engine Service Manual.pdf
New Holland Lx465 Engine Service Manual.pdf
Service Repair Manual
John Deere 185 Hydrostatic Transmission Service Manual.pdf
John Deere 185 Hydrostatic Transmission Service Manual.pdf
Service Repair Manual

More Related Content

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

ch 2. Python module
ch 2. Python module
Prof .Pragati Khade
An Introduction : Python
An Introduction : Python
Raghu Kumar
Python for Beginners
Python for Beginners
DrRShaliniVISTAS
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
UadAccount
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
Modules and packages in python
Modules and packages in python
TMARAGATHAM
Modules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
Modules in Python.docx
Modules in Python.docx
manohar25689
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
rajkumar2792005
package module in the python environement.pptx
package module in the python environement.pptx
MuhammadAbdullah311866
packages.pptx
packages.pptx
SHAIKIRFAN715544
Pythonintroduction
Pythonintroduction
-jyothish kumar sirigidi
Python lec1
Python lec1
Swarup Ghosh
Introduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3
Intro-to-Python-Part-1-first-part-edition.pdf
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
Python module 3, b.tech 5th semester ppt
Python module 3, b.tech 5th semester ppt
course5325
Introduction on basic python and it's application
Introduction on basic python and it's application
sriram2110
Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12
JAYASURYANSHUPEDDAPA
CLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal
An Introduction : Python
An Introduction : Python
Raghu Kumar
Using-Python-Libraries.9485146.powerpoint.pptx
Using-Python-Libraries.9485146.powerpoint.pptx
UadAccount
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Python Programming - IV. Program Components (Functions, Classes, Modules, Pac...
Ranel Padon
Modules and Packages in Python_Basics.pdf
Modules and Packages in Python_Basics.pdf
RavindraTambe3
Modules and packages in python
Modules and packages in python
TMARAGATHAM
Modules and Packages in Python Programming Language.pptx
Modules and Packages in Python Programming Language.pptx
arunavamukherjee9999
Modules in Python.docx
Modules in Python.docx
manohar25689
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
COMPUTER SCIENCE SUPPORT MATERIAL CLASS 12.pdf
rajkumar2792005
package module in the python environement.pptx
package module in the python environement.pptx
MuhammadAbdullah311866
Introduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3
Intro-to-Python-Part-1-first-part-edition.pdf
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
Python module 3, b.tech 5th semester ppt
Python module 3, b.tech 5th semester ppt
course5325
Introduction on basic python and it's application
Introduction on basic python and it's application
sriram2110
Functions_in_Python.pdf text CBSE class 12
Functions_in_Python.pdf text CBSE class 12
JAYASURYANSHUPEDDAPA
CLASS-11 & 12 ICT PPT Functions in Python.pptx
CLASS-11 & 12 ICT PPT Functions in Python.pptx
seccoordpal

Recently uploaded (20)

New Holland Lx465 Engine Service Manual.pdf
New Holland Lx465 Engine Service Manual.pdf
Service Repair Manual
John Deere 185 Hydrostatic Transmission Service Manual.pdf
John Deere 185 Hydrostatic Transmission Service Manual.pdf
Service Repair Manual
John Deere 160 Lawn Tractor Electrical Manual.pdf
John Deere 160 Lawn Tractor Electrical Manual.pdf
Service Repair Manual
John Deere 120C Excavator Operation and Test Service Manual
John Deere 120C Excavator Operation and Test Service Manual
Service Repair Manual
Modern Cars Are Slowly Becoming Computers On Wheels - Here's Why!
Modern Cars Are Slowly Becoming Computers On Wheels - Here's Why!
jennifermiller8137
Caterpillar Cat 428D BACKHOE LOADER (Prefix BNS) Service Repair Manual Instan...
Caterpillar Cat 428D BACKHOE LOADER (Prefix BNS) Service Repair Manual Instan...
xue582shao
Caterpillar Cat 318B LN Excavator (Prefix 7KZ) Service Repair Manual Instant ...
Caterpillar Cat 318B LN Excavator (Prefix 7KZ) Service Repair Manual Instant ...
nu174136zhao
Caterpillar Cat 325L EXCAVATOR (Prefix 6RM) Service Repair Manual Instant Dow...
Caterpillar Cat 325L EXCAVATOR (Prefix 6RM) Service Repair Manual Instant Dow...
er6juheng
Caterpillar Cat 329D2L Excavator (Prefix RGA) Service Repair Manual Instant D...
Caterpillar Cat 329D2L Excavator (Prefix RGA) Service Repair Manual Instant D...
su09540343
Daewoo doosan mega 400-v Electrical System repair manual.pdf
Daewoo doosan mega 400-v Electrical System repair manual.pdf
Service Repair Manual
Caterpillar Cat 311C U Excavator (Prefix CKE) Service Repair Manual Instant D...
Caterpillar Cat 311C U Excavator (Prefix CKE) Service Repair Manual Instant D...
nu174136zhao
Caterpillar Cat 304E Mini Hydraulic Excavator (Prefix TSR) Service Repair Man...
Caterpillar Cat 304E Mini Hydraulic Excavator (Prefix TSR) Service Repair Man...
jie2404li
Restore Porsche Performance How to Spot and Fix Fuel Injection System Failures
Restore Porsche Performance How to Spot and Fix Fuel Injection System Failures
Bay Diagnostic
Caterpillar Cat 345B Series II Excavator (Prefix DCW) Service Repair Manual I...
Caterpillar Cat 345B Series II Excavator (Prefix DCW) Service Repair Manual I...
yunsuij35094
Caterpillar Cat 318D2 L Excavator (Prefix HAH) Service Repair Manual Instant ...
Caterpillar Cat 318D2 L Excavator (Prefix HAH) Service Repair Manual Instant ...
nu174136zhao
Daewoo doosan mega 300 v wheel loader operator and maintenance manual.pdf
Daewoo doosan mega 300 v wheel loader operator and maintenance manual.pdf
Service Repair Manual
John Deere 175 Power Train Service Manual.pdf
John Deere 175 Power Train Service Manual.pdf
Service Repair Manual
New Holland Lx465 Problems Repair Manual.pdf
New Holland Lx465 Problems Repair Manual.pdf
Service Repair Manual
Caterpillar Cat 329D2 Excavator (Prefix THW) Service Repair Manual Instant Do...
Caterpillar Cat 329D2 Excavator (Prefix THW) Service Repair Manual Instant Do...
su09540343
Caterpillar Cat 318B N Excavator (Prefix 7KZ) Service Repair Manual Instant D...
Caterpillar Cat 318B N Excavator (Prefix 7KZ) Service Repair Manual Instant D...
nu174136zhao
New Holland Lx465 Engine Service Manual.pdf
New Holland Lx465 Engine Service Manual.pdf
Service Repair Manual
John Deere 185 Hydrostatic Transmission Service Manual.pdf
John Deere 185 Hydrostatic Transmission Service Manual.pdf
Service Repair Manual
John Deere 160 Lawn Tractor Electrical Manual.pdf
John Deere 160 Lawn Tractor Electrical Manual.pdf
Service Repair Manual
John Deere 120C Excavator Operation and Test Service Manual
John Deere 120C Excavator Operation and Test Service Manual
Service Repair Manual
Modern Cars Are Slowly Becoming Computers On Wheels - Here's Why!
Modern Cars Are Slowly Becoming Computers On Wheels - Here's Why!
jennifermiller8137
Caterpillar Cat 428D BACKHOE LOADER (Prefix BNS) Service Repair Manual Instan...
Caterpillar Cat 428D BACKHOE LOADER (Prefix BNS) Service Repair Manual Instan...
xue582shao
Caterpillar Cat 318B LN Excavator (Prefix 7KZ) Service Repair Manual Instant ...
Caterpillar Cat 318B LN Excavator (Prefix 7KZ) Service Repair Manual Instant ...
nu174136zhao
Caterpillar Cat 325L EXCAVATOR (Prefix 6RM) Service Repair Manual Instant Dow...
Caterpillar Cat 325L EXCAVATOR (Prefix 6RM) Service Repair Manual Instant Dow...
er6juheng
Caterpillar Cat 329D2L Excavator (Prefix RGA) Service Repair Manual Instant D...
Caterpillar Cat 329D2L Excavator (Prefix RGA) Service Repair Manual Instant D...
su09540343
Daewoo doosan mega 400-v Electrical System repair manual.pdf
Daewoo doosan mega 400-v Electrical System repair manual.pdf
Service Repair Manual
Caterpillar Cat 311C U Excavator (Prefix CKE) Service Repair Manual Instant D...
Caterpillar Cat 311C U Excavator (Prefix CKE) Service Repair Manual Instant D...
nu174136zhao
Caterpillar Cat 304E Mini Hydraulic Excavator (Prefix TSR) Service Repair Man...
Caterpillar Cat 304E Mini Hydraulic Excavator (Prefix TSR) Service Repair Man...
jie2404li
Restore Porsche Performance How to Spot and Fix Fuel Injection System Failures
Restore Porsche Performance How to Spot and Fix Fuel Injection System Failures
Bay Diagnostic
Caterpillar Cat 345B Series II Excavator (Prefix DCW) Service Repair Manual I...
Caterpillar Cat 345B Series II Excavator (Prefix DCW) Service Repair Manual I...
yunsuij35094
Caterpillar Cat 318D2 L Excavator (Prefix HAH) Service Repair Manual Instant ...
Caterpillar Cat 318D2 L Excavator (Prefix HAH) Service Repair Manual Instant ...
nu174136zhao
Daewoo doosan mega 300 v wheel loader operator and maintenance manual.pdf
Daewoo doosan mega 300 v wheel loader operator and maintenance manual.pdf
Service Repair Manual
John Deere 175 Power Train Service Manual.pdf
John Deere 175 Power Train Service Manual.pdf
Service Repair Manual
New Holland Lx465 Problems Repair Manual.pdf
New Holland Lx465 Problems Repair Manual.pdf
Service Repair Manual
Caterpillar Cat 329D2 Excavator (Prefix THW) Service Repair Manual Instant Do...
Caterpillar Cat 329D2 Excavator (Prefix THW) Service Repair Manual Instant Do...
su09540343
Caterpillar Cat 318B N Excavator (Prefix 7KZ) Service Repair Manual Instant D...
Caterpillar Cat 318B N Excavator (Prefix 7KZ) Service Repair Manual Instant D...
nu174136zhao
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 LIBRARYS FUNCTIONS AND MODULES Pythons 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 鍖le 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 scienti鍖c 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 modules 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 modules 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 de鍖ned in this module. Pie () is a well-known mathematical constant, which is de鍖ned 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 de鍖ned 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 鍖oat number between 0.0 and 1.0. random.random(): Generates a random 鍖oat 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 speci鍖ed 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 鍖rst character to upper case count() Returns the number of times a speci鍖ed value occurs in a string 鍖nd() Searches the string for a speci鍖ed value and returns the position of where it was found index() Searches the string for a speci鍖ed 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 speci鍖ed value is replaced with a speci鍖ed value split() Splits the string at the speci鍖ed separator, and returns a list
  • 9. Relation Between Python Libraries, Module and Package A module is a 鍖le containing python de鍖nition, functions, variables, classes and statements. The extension of this 鍖le 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 鍖le containing python de鍖nition, functions, variables, classes and statements. The extension of this 鍖le 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 de鍖ne a Namespace it is necessary to de鍖ne its name. Python name is a kind of identi鍖er 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 鍖les area.py and volume.py 2.In the same directory we will put another 鍖le named __init__.py 3.__init__.py is necessary because this is the 鍖le which tells Python that directory is package. And this 鍖le 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 ( )