SlideShare a Scribd company logo
CHAPTER 4
SELF LEARNING
PRESENTATION.
.pptx Format
All images used in this presentation
are from the public domain
Friends,
Module 1 assigning to Aswin
Module 3 and 5 goes to Naveen
Module 4 to Abhishek, 2 to Sneha
and .., Abhijith will lead you.
I need this
code again
in another
program.
Modules, packages, and libraries are
all different ways to reuse a code.
Modules
Packages
libraries
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.
Look at the board. There are
some functions, classes, constant
and some other statements.
Absolutely this is a module.
Module is a collection
of functions, classes,
constants and other
statements.
Write the code on the board
in a file and save it with a
name with .py suffix.
It becomes a module.
Yes2. I want to write
some more module
files.
Can you try your
own modules ?
Good. That is Package.
A group of modules saved in a
folder is called package.
I want a package contains
my own modules.
Collection of modules
saved in a folder, are
called package.
Library is a collection of packages.
Suppose we write more packages about
anything. It will become a library. In
general, the terms package and library
have the same meaning.
PYTHON has rich libraries.
,
.
The Python Standard Library contains
built-in data, functions, and many modules.
All are part of the Python installation.
Basic Contents of Standard Library.
Built-in
Data,
functions
+ more
Module to import
1. Math module
2. Cmath module
3. Random module
4. Statistics module
5. Urllib module
and
print ( "10 + 20 = ", 10 + 20 )
print ( "Cube of 2 is ", 2 ** 3 )
import math
print ("Square root of 25 is ", math.sqrt(25) )
print ("Cube of 2 is ", math.pow(2,3) )
print(), input(),
10 + 20 are basic operation.
No need to import anything.
sqrt () and pow () are defined in
Math module. So need to
import math modules.
We use the
Statement to import other
modules into our programs.
hex ( Integer Argument )
oct ( Integer Argument )
int ( string / float Argument )
round ( )
Examples of Built-in Function.
Accept an integer in any
system and returns its
octal equivalent as string.
>>> oct ( 10 )
OUTPUT : ‘0o12’
Accept an integer in any system and returns
its Hexadecimal equivalent as string.
>>> hex ( 10 )
OUTPUT : ‘0xa’
The int() function returns
integer value of given value.
The given float number is rounded
to specified number of
decimal places.
>>> int ( 3.14 )
OUTPUT : 3
>>> round ( 3.65,0 )
OUTPUT : 4.0
In oct, 1, 2, 3, 4,
5, 6, 7, What
next ?
oct(),hex() and bin() Functions.
Don't worry. you just count 1 to 20 using
for a in range(1,21) And use hex() and oct()
functions. The computer will do everything for you.
Octal system has only 8
digits. They are 0 to 7. after 7,
write 10 for 8, 11 for 9, 12 for
10 etc.
Hexadecimal system has 16
digits. They are 0 to 9 and 'a'
for 10, 'b' for 11... 'f' for 15.
After 15, write 10 for 16, 11 for
print ("Numbering System Table")
print("column 1: Decimal System, col2 : Octal, col3: Hex, col4: Binary")
for a in range(1,25):
print(a, oct(a), hex(a), bin(a) )
Numbering System Table
column 1 :Decimal System, col2 : Octal,
col3: Hex, col4: Binary
1 0o1 0x1 0b1
2 0o2 0x2 0b10
3 0o3 0x3 0b11
4 0o4 0x4 0b100
5 0o5 0x5 0b101
6 0o6 0x6 0b110
16 0o20 0x10 0b10000
17 0o21 0x11 0b10001
18 0o22 0x12 0b10010
19 0o23 0x13 0b10011
20 0o24 0x14 0b10100
21 0o25 0x15 0b10101
22 0o26 0x16 0b10110
23 0o27 0x17 0b10111
24 0o30 0x18 0b11000
oct() convert given value to octal system.
hex() convert given value to Hexadecimal system.
bin() convert given value to Binary system.
OUTPUT
CODE
int ( float/string Argument )
round (float , No of Decimals)
int () and round () Function.
The int() function returns integer value
(No decimal places) of given value. The given
value may be an integer, float or a string like “123”
The given float number is rounded to specified
number of decimal places. If the ignoring number is
above .5 ( >=.5) then the digit before it will be added by 1.
>>> int ( 3.14 )
OUTPUT : 3
>>> int (10/3)
OUTPUT : 3
>>> int( “123” )
OUTPUT : 123
>>> round ( 3.65 , 0 )
OUTPUT : 4.0
Join the words “lion”, “tiger” and
“leopard” together.
Replace all "a" in “Mavelikkara” with "A".
Split the line 'India is my motherland'
into separate words.
“anil” + “kumar” = “anil kumar”,
“anil” * 3 = “anilanilanil”. These are
the basic operations of a string.
string.split() function splits a string into a list.
>>> x = "All knowledge is within us.“
>>>
We get the list ['All', 'knowledge', 'is', 'within', 'us.']
Wrong use Right use
Prefix
>>> x = "Mathew,Krishna,David,Ram"
>>> x.split( “,” )
We get the list ['Mathew', 'Krishna', 'David', 'Ram']
Cut when
you see “n“.
>>> x = "MathewnKrishnanDavidnRam"
>>> x.split( “n” )
We get the list ['Mathew', 'Krishna', 'David', 'Ram']
>>> x = "MAVELIKARA"
>>> x.split("A")
We get the list ['M', 'VELIK', 'R', '']
"MAVELIKARA" Is it
Fun
?
string.join() joins a set of string into a single string.
Delimit string.join ( collection of string )
“,”. join ( [‘Item1’, ‘Item2’, ‘Item3’] )
‘Item1’
‘Item1,Item2’
1
2
3
Item1,Item2,Item3
End
>>> a = ['Matthew', 'Krishna', 'David','Ram']
>>> ",".join(a) OUTPUT : 'Matthew,Krishna,David,Ram'
Do it in Python.
>>> a = ['Trissur','Ernakulam','Kottayam', 'Mavelikara' ]
>>>> "->".join(a)
'Trissur->Ernakulam->Kottayam->Mavelikara'
Can you change
zebra to cobra?
replace () Function. replace () Function.
function replaces a phrase with
another phrase.
string.replace(what, with, count )
What to replace?
Replace with what?
How many
replacement is
needed.(optional)
>>> ‘zebra’.replace(‘ze’,’co’)
cobra zebra becomes cobra
>>> ‘cobra’.replace(‘co’,’ze’)
zebra cobra becomes zebra
Modules such as math, cmath, random, statistics, urllib are
not an integral part of Python Interpreter. But they are
part of the Python installation. If we need them,
import them into our program and use them.
We use "Import” statement to import
Other modules into our programs.
It has many forms. We will learn in detail later.
Syntax is import < module Name >
E.g. import math
import random
Python does a series of actions when you import module,
They are
The code of importing modules is interpreted
and executed.
Defined functions and variables in the
module are now available.
A new namespace is setup for importing modules.
A namespace is a dictionary that contains the names and definitions
of defined functions and variables. Names are like keys and
definitions are values. It will avoid ambiguity between 2 names.
I teach 2 Abhijit. one is in class XI-B and
other is in class XII-A. How can I write
theirname without ambiguity.
class XI-B.Abhijit class XII-A.Abhijit
Are not Ashwin in 12.B?
Your Reg. No 675323.
No Sir, Check
the list of 12.A
Who is കുഴിക്കാലായിൽ
അബ്രഹാാം(K M Abraham)
He is a member of
കുഴിക്കാലായിൽ
family.
An object (variable, functions
etc.) defined in a namespace is
associated with that
namespace. This way, the same
identifier can be defined in
multiple namespaces.
>>> math.
Output : 5
>>> math.pi
Output :3.141592653589793
Google K.M. Abraham.
Name of
Namespace
Object in that
Namespace
math
math and cmath modules covers many mathematical
functions.
and .
More than 45 functions and 5 constants are defined in it.
The use of these functions can be understood by their
name itself.
2. Place (Namespace) before function name.
1. import math
X = sqrt(25)
Name of
Namespace
Object in that
Namespace
>>> locals()
{'__name__': '__main__', '__doc__': None, '__package__': None,
'__loader__': <class '_frozen_importlib.BuiltinImporter'>,
'__spec__': None, '__annotations__': {}, '__builtins__': <module
'builtins' (built-in)>}
>>> import math
>>> locals()
{'__name__': '__main__', '__doc__': None, '__package__': None,
'__loader__': <class '_frozen_importlib.BuiltinImporter'>,
'__spec__': None, '__annotations__': {}, '__builtins__': <module
'builtins' (built-in)>, 'math': <module 'math' (built-in)>}
>>>
>>> help(math)
Traceback (most recent call last): File "<pyshell#1>", line 1, in <module>
help(math)
NameError: name 'math' is not defined
>>> import math
>>> help (math)
Help on built-in module math:
NAME
math
DESCRIPTION
This module provides access to the mathematical functions
defined by the C standard.
FUNCTIONS.
import math
The value without –ve / +ve symbol is called
absolute value. Both functions give absolute value, while fabs () always give a float
value, but abs () gives either float or int depending on the argument.
>>> abs(-5.5) >>> abs(5)
Output : 5.5 5
>>> math.fabs(5) >>> math.fabs(5.5)
Output : 5.0 5.5
Returns factorial value
of given Integer. Error will occur if you enter a -ve or a float value.
>>> >>> math.factorial(-5)
Output : 120 >>> math.factorial(5.5)
Wrong use
Right use
Abs() is built-
in function.
Interesting, right?
This is just a sneak preview of the full presentation. We hope
you like it! To see the rest of it, just click here to view it in full
on PowerShow.com. Then, if you’d like, you can also log in to
PowerShow.com to download the entire presentation for free.

More Related Content

Similar to Using-Python-Libraries.9485146.powerpoint.pptx

Data structures KTU chapter2.PPT
Data structures KTU chapter2.PPTData structures KTU chapter2.PPT
Data structures KTU chapter2.PPTAlbin562191
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Guy Lebanon
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202Mahmoud Samir Fayed
 
sonam Kumari python.ppt
sonam Kumari python.pptsonam Kumari python.ppt
sonam Kumari python.pptssuserd64918
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11Henry Schreiner
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnArnaud Joly
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notesGOKULKANNANMMECLECTC
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdfsimenehanmut
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyworldchannel
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schoolsDan Bowen
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2Prerna Sharma
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfdata2businessinsight
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossumoscon2007
 

Similar to Using-Python-Libraries.9485146.powerpoint.pptx (20)

python modules1522.pdf
python modules1522.pdfpython modules1522.pdf
python modules1522.pdf
 
Data structures KTU chapter2.PPT
Data structures KTU chapter2.PPTData structures KTU chapter2.PPT
Data structures KTU chapter2.PPT
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
Python basics
Python basicsPython basics
Python basics
 
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.8 book - Part 94 of 202
 
sonam Kumari python.ppt
sonam Kumari python.pptsonam Kumari python.ppt
sonam Kumari python.ppt
 
Python for Beginners
Python  for BeginnersPython  for Beginners
Python for Beginners
 
What's new in Python 3.11
What's new in Python 3.11What's new in Python 3.11
What's new in Python 3.11
 
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learnNumerical tour in the Python eco-system: Python, NumPy, scikit-learn
Numerical tour in the Python eco-system: Python, NumPy, scikit-learn
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
Programming python quick intro for schools
Programming python quick intro for schoolsProgramming python quick intro for schools
Programming python quick intro for schools
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdf
 
ch 2. Python module
ch 2. Python module ch 2. Python module
ch 2. Python module
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxShajedul Islam Pavel
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleCeline George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFVivekanand Anglo Vedic Academy
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfTamralipta Mahavidyalaya
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Forest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDFForest and Wildlife Resources Class 10 Free Study Material PDF
Forest and Wildlife Resources Class 10 Free Study Material PDF
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 

Using-Python-Libraries.9485146.powerpoint.pptx

  • 1. CHAPTER 4 SELF LEARNING PRESENTATION. .pptx Format All images used in this presentation are from the public domain
  • 2.
  • 3.
  • 4. Friends, Module 1 assigning to Aswin Module 3 and 5 goes to Naveen Module 4 to Abhishek, 2 to Sneha and .., Abhijith will lead you.
  • 5. I need this code again in another program.
  • 6. Modules, packages, and libraries are all different ways to reuse a code. Modules Packages libraries
  • 7. A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Look at the board. There are some functions, classes, constant and some other statements. Absolutely this is a module. Module is a collection of functions, classes, constants and other statements.
  • 8. Write the code on the board in a file and save it with a name with .py suffix. It becomes a module.
  • 9. Yes2. I want to write some more module files. Can you try your own modules ? Good. That is Package.
  • 10. A group of modules saved in a folder is called package. I want a package contains my own modules. Collection of modules saved in a folder, are called package.
  • 11. Library is a collection of packages. Suppose we write more packages about anything. It will become a library. In general, the terms package and library have the same meaning.
  • 12. PYTHON has rich libraries. , .
  • 13. The Python Standard Library contains built-in data, functions, and many modules. All are part of the Python installation. Basic Contents of Standard Library.
  • 14. Built-in Data, functions + more Module to import 1. Math module 2. Cmath module 3. Random module 4. Statistics module 5. Urllib module and
  • 15. print ( "10 + 20 = ", 10 + 20 ) print ( "Cube of 2 is ", 2 ** 3 ) import math print ("Square root of 25 is ", math.sqrt(25) ) print ("Cube of 2 is ", math.pow(2,3) ) print(), input(), 10 + 20 are basic operation. No need to import anything. sqrt () and pow () are defined in Math module. So need to import math modules. We use the Statement to import other modules into our programs.
  • 16. hex ( Integer Argument ) oct ( Integer Argument ) int ( string / float Argument ) round ( ) Examples of Built-in Function. Accept an integer in any system and returns its octal equivalent as string. >>> oct ( 10 ) OUTPUT : ‘0o12’ Accept an integer in any system and returns its Hexadecimal equivalent as string. >>> hex ( 10 ) OUTPUT : ‘0xa’ The int() function returns integer value of given value. The given float number is rounded to specified number of decimal places. >>> int ( 3.14 ) OUTPUT : 3 >>> round ( 3.65,0 ) OUTPUT : 4.0 In oct, 1, 2, 3, 4, 5, 6, 7, What next ?
  • 17. oct(),hex() and bin() Functions. Don't worry. you just count 1 to 20 using for a in range(1,21) And use hex() and oct() functions. The computer will do everything for you. Octal system has only 8 digits. They are 0 to 7. after 7, write 10 for 8, 11 for 9, 12 for 10 etc. Hexadecimal system has 16 digits. They are 0 to 9 and 'a' for 10, 'b' for 11... 'f' for 15. After 15, write 10 for 16, 11 for
  • 18. print ("Numbering System Table") print("column 1: Decimal System, col2 : Octal, col3: Hex, col4: Binary") for a in range(1,25): print(a, oct(a), hex(a), bin(a) ) Numbering System Table column 1 :Decimal System, col2 : Octal, col3: Hex, col4: Binary 1 0o1 0x1 0b1 2 0o2 0x2 0b10 3 0o3 0x3 0b11 4 0o4 0x4 0b100 5 0o5 0x5 0b101 6 0o6 0x6 0b110 16 0o20 0x10 0b10000 17 0o21 0x11 0b10001 18 0o22 0x12 0b10010 19 0o23 0x13 0b10011 20 0o24 0x14 0b10100 21 0o25 0x15 0b10101 22 0o26 0x16 0b10110 23 0o27 0x17 0b10111 24 0o30 0x18 0b11000 oct() convert given value to octal system. hex() convert given value to Hexadecimal system. bin() convert given value to Binary system. OUTPUT CODE
  • 19. int ( float/string Argument ) round (float , No of Decimals) int () and round () Function. The int() function returns integer value (No decimal places) of given value. The given value may be an integer, float or a string like “123” The given float number is rounded to specified number of decimal places. If the ignoring number is above .5 ( >=.5) then the digit before it will be added by 1. >>> int ( 3.14 ) OUTPUT : 3 >>> int (10/3) OUTPUT : 3 >>> int( “123” ) OUTPUT : 123 >>> round ( 3.65 , 0 ) OUTPUT : 4.0
  • 20. Join the words “lion”, “tiger” and “leopard” together. Replace all "a" in “Mavelikkara” with "A". Split the line 'India is my motherland' into separate words. “anil” + “kumar” = “anil kumar”, “anil” * 3 = “anilanilanil”. These are the basic operations of a string.
  • 21. string.split() function splits a string into a list. >>> x = "All knowledge is within us.“ >>> We get the list ['All', 'knowledge', 'is', 'within', 'us.'] Wrong use Right use Prefix
  • 22. >>> x = "Mathew,Krishna,David,Ram" >>> x.split( “,” ) We get the list ['Mathew', 'Krishna', 'David', 'Ram'] Cut when you see “n“. >>> x = "MathewnKrishnanDavidnRam" >>> x.split( “n” ) We get the list ['Mathew', 'Krishna', 'David', 'Ram'] >>> x = "MAVELIKARA" >>> x.split("A") We get the list ['M', 'VELIK', 'R', ''] "MAVELIKARA" Is it Fun ?
  • 23. string.join() joins a set of string into a single string. Delimit string.join ( collection of string ) “,”. join ( [‘Item1’, ‘Item2’, ‘Item3’] ) ‘Item1’ ‘Item1,Item2’ 1 2 3 Item1,Item2,Item3 End >>> a = ['Matthew', 'Krishna', 'David','Ram'] >>> ",".join(a) OUTPUT : 'Matthew,Krishna,David,Ram'
  • 24. Do it in Python. >>> a = ['Trissur','Ernakulam','Kottayam', 'Mavelikara' ] >>>> "->".join(a) 'Trissur->Ernakulam->Kottayam->Mavelikara'
  • 25. Can you change zebra to cobra? replace () Function. replace () Function. function replaces a phrase with another phrase. string.replace(what, with, count ) What to replace? Replace with what? How many replacement is needed.(optional) >>> ‘zebra’.replace(‘ze’,’co’) cobra zebra becomes cobra >>> ‘cobra’.replace(‘co’,’ze’) zebra cobra becomes zebra
  • 26. Modules such as math, cmath, random, statistics, urllib are not an integral part of Python Interpreter. But they are part of the Python installation. If we need them, import them into our program and use them. We use "Import” statement to import Other modules into our programs. It has many forms. We will learn in detail later. Syntax is import < module Name > E.g. import math import random
  • 27. Python does a series of actions when you import module, They are The code of importing modules is interpreted and executed. Defined functions and variables in the module are now available. A new namespace is setup for importing modules.
  • 28. A namespace is a dictionary that contains the names and definitions of defined functions and variables. Names are like keys and definitions are values. It will avoid ambiguity between 2 names. I teach 2 Abhijit. one is in class XI-B and other is in class XII-A. How can I write theirname without ambiguity. class XI-B.Abhijit class XII-A.Abhijit
  • 29. Are not Ashwin in 12.B? Your Reg. No 675323. No Sir, Check the list of 12.A
  • 30. Who is കുഴിക്കാലായിൽ അബ്രഹാാം(K M Abraham) He is a member of കുഴിക്കാലായിൽ family. An object (variable, functions etc.) defined in a namespace is associated with that namespace. This way, the same identifier can be defined in multiple namespaces. >>> math. Output : 5 >>> math.pi Output :3.141592653589793 Google K.M. Abraham. Name of Namespace Object in that Namespace
  • 31. math math and cmath modules covers many mathematical functions. and . More than 45 functions and 5 constants are defined in it. The use of these functions can be understood by their name itself. 2. Place (Namespace) before function name. 1. import math X = sqrt(25) Name of Namespace Object in that Namespace
  • 32. >>> locals() {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>} >>> import math >>> locals() {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, 'math': <module 'math' (built-in)>} >>>
  • 33. >>> help(math) Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> help(math) NameError: name 'math' is not defined >>> import math >>> help (math) Help on built-in module math: NAME math DESCRIPTION This module provides access to the mathematical functions defined by the C standard.
  • 34. FUNCTIONS. import math The value without –ve / +ve symbol is called absolute value. Both functions give absolute value, while fabs () always give a float value, but abs () gives either float or int depending on the argument. >>> abs(-5.5) >>> abs(5) Output : 5.5 5 >>> math.fabs(5) >>> math.fabs(5.5) Output : 5.0 5.5 Returns factorial value of given Integer. Error will occur if you enter a -ve or a float value. >>> >>> math.factorial(-5) Output : 120 >>> math.factorial(5.5) Wrong use Right use Abs() is built- in function.
  • 35. Interesting, right? This is just a sneak preview of the full presentation. We hope you like it! To see the rest of it, just click here to view it in full on PowerShow.com. Then, if you’d like, you can also log in to PowerShow.com to download the entire presentation for free.