SlideShare a Scribd company logo
Computer Science
Grade XII
Frame-
work
Libr-
ary1
Libr-
ary2
Pack-
age1
Pack-
age2
Pack-
age3
Pack-
age4
mod-
ule1
mod-
ule2
Framework=multiple library
Library=multiple packages
Package=multiple module
Module=multiple function/class
Using
Python Libraries
must be clear
while
Following
terms
project/program.
1.Module
2.Package
3.Library
4.Framework
1. Using
Module
developing any
python
-It is a file which contains
python functions/global
variables/clases etc. It is just .py file which has python executable code /
statement.For example: Let’s create a file usermodule.py
def hello_message(user_name):
return “Hello " + name
Now we can import usermodule.py module either in python interpreter or
other py file.
import usermodule
print usermodule.hello_message(“India")
Using
Python Libraries
How to import modules in Python?
Python module can be accessed in any of following way.
●
Python import statement import math
print(“2 to the power 3 is ", math.pow(2,3))
Just similar to math ,user defined module can be accessed using
import
statement
●
Import with renaming import math as mt
print(“2 to the power 3 is ", mt.pow(2,3))
print(“2 to the power 3 is ", pow(2,3))
Using python libraries.pptx , easy ppt to study class 12
Using
Python Libraries
2. Using Package - It is namespace that contains multiple package or modules. It is a
directory which contains a special file init .py
Let’s create a directory geometry. Now this package contains multiple packages / modules to handle
user related requests.
geometry/ # top level package
init.py
rectangle/ # first subpackage
init .py
area_rect.py
perimeter_rect.py
circle/ # second subpackage
init.py
area_circ.py
perimeter_circ.py
Now we can import it in following way in other .py file from
geometry.rectangle import area_rect
from geometry.circle import perimeter_circ
Using
Python Libraries
3. Using Library
It is a collection of various packages. Conceptually,There is no difference between
package and python library.In Python, a library is used loosely to describe a
collection of the core modules.
‘standard library‘ of Python language comes bundled with the core Python
distribution are collection of exact syntax, token and semantics of the Python
language . The python standard library lists down approx more than 200 such core
modules that form the core of Python.
“Additional libraries” refer to those optional components that are commonly
included in Python distributions.
The Python installers automatically adds the standard library and some additional
libraries.
The additional library is generally provided as a collection of packages. To use such
additional library we have to use packaging tools like easyinstall or pip to install such
additional libraries.
Using
Python Libraries
3. Create library – create following directory and files structure to learn library creation & use
C:/mylib/Library1(dir)----------|
functions1/classs1
functions2/classs2
|
|
|
|
|package1(dir.)------|module1.py
| |module2.py
|
|package2(dir.)------|module3.p functions3/classs3
functions4/classs4
| init .py(blank file) |module4.py
|mylibcall.py
def moduletest2():
print("from module2")
from library1.package1 import module2
print(module2.moduletest2())
Define a function moduletest2() in module2.py file and call this
function in mylibcall.py file as a part of library1 library.Now run mylibcall.py file
It will call moduletest2() method and display-’from module2’ message.
Please make sure that a blank file with init .py is created.
Set as environment variable of library1 to call any where(path) on the system
Using
Python Libraries
4. Using Framework
Framework is like a collection of various libraries which architects
some more component.
For e.g. Django which has various in-built libraries like
Auth, user, database connector etc.
Recursion
Python also accepts function recursion, which means a
defined function can call itself. Recursion is a common
mathematical and programming concept. It means that a
function calls itself. This has the benefit of meaning that
you can loop through data to reach a result.
# Program to find Sum of n numbers
def sum(n):
if n <= 1:
return n
else:
return n + sum(n-1)
num = int(input("Enter a number: "))
print("The sum is: ", sum(num))
# Program to print factorial of a number
def recursive_factorial(n):
if n == 1:
return n
else:
return n * recursive_factorial(n-1)
# user input
num = 6
# check if the input is valid or not
if num < 0:
print("Invalid input ! Please enter a positive number.")
elif num == 0:
print("Factorial of number 0 is 1")
else:
print("Factorial of number", num, "=", recursive_factorial(num))
# Recursive function for fibonacci Series
def recursive_fibonacci(n):
if n <= 1:
return n
else:
return(recursive_fibonacci(n-1) + recursive_fibonacci(n-2))
n_terms = 10
# check if the number of terms is valid
if n_terms <= 0:
print("Invalid input ! Please input a positive value")
else:
print("Fibonacci series:")
for i in range(n_terms):
print(recursive_fibonacci(i))
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12
Using python libraries.pptx , easy ppt to study class 12

More Related Content

PDF
Python. libraries. modules. and. all.pdf
PPTX
Class 12 CBSE Chapter: python libraries.pptx
PDF
class 12 Libraries in dfbdsbsdbdfbdfdfdf.pdf
PDF
Using Python Libraries.pdf
PDF
Python libraries
PDF
Unit-2 Introduction of Modules and Packages.pdf
PDF
PPTX
Unit 2function in python.pptx
Python. libraries. modules. and. all.pdf
Class 12 CBSE Chapter: python libraries.pptx
class 12 Libraries in dfbdsbsdbdfbdfdfdf.pdf
Using Python Libraries.pdf
Python libraries
Unit-2 Introduction of Modules and Packages.pdf
Unit 2function in python.pptx

Similar to Using python libraries.pptx , easy ppt to study class 12 (20)

PPTX
Object oriented programming design and implementation
PPT
python language programming presentation
PPTX
Chapter 03 python libraries
PDF
Introduction to Python Programming | InsideAIML
PPSX
Modules and packages in python
PPTX
An Introduction : Python
PPTX
Unit 2function in python.pptx
PDF
W-334535VBE242 Using Python Libraries.pdf
PPTX
Introduction to Python Programming
PPTX
package module in the python environement.pptx
PPTX
Introduction to python programming 2
PPTX
CLASS-11 & 12 ICT PPT Functions in Python.pptx
PPTX
Functions_in_Python.pptx
PDF
Anton Kasyanov, Introduction to Python, Lecture3
PDF
Functions_in_Python.pdf text CBSE class 12
PPTX
CBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakash
PDF
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
PPTX
Python programming
PDF
Modules 101
PPT
Python Training v2
Object oriented programming design and implementation
python language programming presentation
Chapter 03 python libraries
Introduction to Python Programming | InsideAIML
Modules and packages in python
An Introduction : Python
Unit 2function in python.pptx
W-334535VBE242 Using Python Libraries.pdf
Introduction to Python Programming
package module in the python environement.pptx
Introduction to python programming 2
CLASS-11 & 12 ICT PPT Functions in Python.pptx
Functions_in_Python.pptx
Anton Kasyanov, Introduction to Python, Lecture3
Functions_in_Python.pdf text CBSE class 12
CBSE-Class 12-Ch4 -Using Python Libraries - SasikalaJayaprakash
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Python programming
Modules 101
Python Training v2
Ad

Recently uploaded (20)

PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PDF
annual-report-2024-2025 original latest.
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PDF
Lecture1 pattern recognition............
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
Computer network topology notes for revision
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPTX
Business Acumen Training GuidePresentation.pptx
PDF
Fluorescence-microscope_Botany_detailed content
PPT
Quality review (1)_presentation of this 21
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
Data_Analytics_and_PowerBI_Presentation.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
annual-report-2024-2025 original latest.
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
IB Computer Science - Internal Assessment.pptx
STUDY DESIGN details- Lt Col Maksud (21).pptx
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Lecture1 pattern recognition............
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
Clinical guidelines as a resource for EBP(1).pdf
Computer network topology notes for revision
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Business Acumen Training GuidePresentation.pptx
Fluorescence-microscope_Botany_detailed content
Quality review (1)_presentation of this 21
Galatica Smart Energy Infrastructure Startup Pitch Deck
Ad

Using python libraries.pptx , easy ppt to study class 12

  • 3. Using Python Libraries must be clear while Following terms project/program. 1.Module 2.Package 3.Library 4.Framework 1. Using Module developing any python -It is a file which contains python functions/global variables/clases etc. It is just .py file which has python executable code / statement.For example: Let’s create a file usermodule.py def hello_message(user_name): return “Hello " + name Now we can import usermodule.py module either in python interpreter or other py file. import usermodule print usermodule.hello_message(“India")
  • 4. Using Python Libraries How to import modules in Python? Python module can be accessed in any of following way. ● Python import statement import math print(“2 to the power 3 is ", math.pow(2,3)) Just similar to math ,user defined module can be accessed using import statement ● Import with renaming import math as mt print(“2 to the power 3 is ", mt.pow(2,3)) print(“2 to the power 3 is ", pow(2,3))
  • 6. Using Python Libraries 2. Using Package - It is namespace that contains multiple package or modules. It is a directory which contains a special file init .py Let’s create a directory geometry. Now this package contains multiple packages / modules to handle user related requests. geometry/ # top level package init.py rectangle/ # first subpackage init .py area_rect.py perimeter_rect.py circle/ # second subpackage init.py area_circ.py perimeter_circ.py Now we can import it in following way in other .py file from geometry.rectangle import area_rect from geometry.circle import perimeter_circ
  • 7. Using Python Libraries 3. Using Library It is a collection of various packages. Conceptually,There is no difference between package and python library.In Python, a library is used loosely to describe a collection of the core modules. ‘standard library‘ of Python language comes bundled with the core Python distribution are collection of exact syntax, token and semantics of the Python language . The python standard library lists down approx more than 200 such core modules that form the core of Python. “Additional libraries” refer to those optional components that are commonly included in Python distributions. The Python installers automatically adds the standard library and some additional libraries. The additional library is generally provided as a collection of packages. To use such additional library we have to use packaging tools like easyinstall or pip to install such additional libraries.
  • 8. Using Python Libraries 3. Create library – create following directory and files structure to learn library creation & use C:/mylib/Library1(dir)----------| functions1/classs1 functions2/classs2 | | | | |package1(dir.)------|module1.py | |module2.py | |package2(dir.)------|module3.p functions3/classs3 functions4/classs4 | init .py(blank file) |module4.py |mylibcall.py def moduletest2(): print("from module2") from library1.package1 import module2 print(module2.moduletest2()) Define a function moduletest2() in module2.py file and call this function in mylibcall.py file as a part of library1 library.Now run mylibcall.py file It will call moduletest2() method and display-’from module2’ message. Please make sure that a blank file with init .py is created. Set as environment variable of library1 to call any where(path) on the system
  • 9. Using Python Libraries 4. Using Framework Framework is like a collection of various libraries which architects some more component. For e.g. Django which has various in-built libraries like Auth, user, database connector etc.
  • 10. Recursion Python also accepts function recursion, which means a defined function can call itself. Recursion is a common mathematical and programming concept. It means that a function calls itself. This has the benefit of meaning that you can loop through data to reach a result.
  • 11. # Program to find Sum of n numbers def sum(n): if n <= 1: return n else: return n + sum(n-1) num = int(input("Enter a number: ")) print("The sum is: ", sum(num))
  • 12. # Program to print factorial of a number def recursive_factorial(n): if n == 1: return n else: return n * recursive_factorial(n-1) # user input num = 6 # check if the input is valid or not if num < 0: print("Invalid input ! Please enter a positive number.") elif num == 0: print("Factorial of number 0 is 1") else: print("Factorial of number", num, "=", recursive_factorial(num))
  • 13. # Recursive function for fibonacci Series def recursive_fibonacci(n): if n <= 1: return n else: return(recursive_fibonacci(n-1) + recursive_fibonacci(n-2)) n_terms = 10 # check if the number of terms is valid if n_terms <= 0: print("Invalid input ! Please input a positive value") else: print("Fibonacci series:") for i in range(n_terms): print(recursive_fibonacci(i))