SlideShare a Scribd company logo
Introduction to Python
What is Python ?
What you can do with it ?
Why it is so popular ?
Free and Open Source
High-level programming language
Free and Open Source
High-level, multi-purpose programming
language
Developed by Guido Van Rossum in the
late 1980s
Python is an interpreter-based
language
Portable, and Extensible
Python can be integrated with other popular programming
technologies like C, C++, Java, ActiveX, and CORBA.
Dynamic Typing
Supports procedural, object-oriented, & functional programming
What you can do with it ?
Desktop
Application
Desktop Application
Mobile Application
9
Why it is so popular ?
High-Level
Huge Community
Large Ecosystem
Platform-Independent
12
What can you do with Python
Develop web applications
Implementing machine learning algorithms such as Scikit-learn, NLTK
and Tensor flow .
Computer vision – Face detection , color detection while using OpenCV and python
Raspberry Pi – You can even build a robot and automate your home.
PyGame – Gaming applications
Is a reserved memory location to store
values
Variable Name
Every value in Python has
data type.
12
Computer memory
Age
0
Address
(index)
Data
Variables are used to store data, they take
memory space based on the type of value we
assigning to them.
Age = 12
16
Names cannot start with a number ,
No spaces in the names, use underscore _ instead
Special characters are not allowed as variable names
income@, <>, ?, ! , (), #,$ ,% , ^, &,*,~,- +
Variable Names and Naming rules
Variables in Python are case sensitive
It can only start with a character or an underscore
20
Name Type Description
Integers int Whole numbers, such as 8 12 400
Floating Point float Numbers with a decimal point 3.3, 14.5, 500.0
Strings Str Ordered sequence of characters
“hello” , “Sammy”, “2000”, “*$LL”
Lists List Ordered sequence of objects [10, “hello world”, 112.4]
Dictionaries dict Unordered key:value pairs {“key”:”value”}
Tuples tup Ordered immutable sequence of objects (30,”Bye”, 111.32)
Sets Set Unordered collection of unique objects (10,20)
Booleans Bool Logical value indicating True or False
Data Types
type()
21
Type conversions
22
>>> float(22//5)
4.0
>>> int(4.5)
4
>>> int(3.9)
3
>>> round(3.9)
4
>>> round(3)
3
strings
23
String formatting
24
There are multiple ways to format strings for printing variables
in them
Myvar= “Hello”
Print(myvar + “World”)
This is knowns as string interpolation
String formatting
25
.fomat() method
Myvar= “Hello”
Print(myvar + “World”)
This is knowns as string interpolation
f-strings (formatted string literals)
String functions
26
index()
casefold()
center()
count()
endswith()
expandtabs()
isalnum()
isalpha()
isdecimal()
isidentifier()
islower()
str1.isnumeric()
str1.join()
Indexing and Slicing with Strings
27
Working with string data type
28
Booleans in Python
30
Booleans are two constant objects
It has only two possible values
Booleans are considered as numeric type in Python
Booleans
1. True
2. False
True == 1
False == 0
None as a Boolean value
Bool(None)
bool(3), bool(-3), bool(0) Nonzero integers are
truth
bool() method to convert a value to Boolean()
31
Boolean operators are those that take Boolean inputs and
return Boolean results
and operator can be defined in terms of ‘not’ and ‘or’
Boolean operators
Boolean operators are and , not, or
or operator can be defined in terms of ‘not’ and ‘and’
Conditional and control flow
Provides us with 3 types of control
statements
Conditional Programming
Used to control the order of execution of the program based on
the values and logic
continue
break
pass
34
expression: It’s the condition that needs to evaluated and
return a boolean (true/false)value.
statement: statement is a general python code that executes if
the expression returns true.
Control Structures
Loop Control Statements
36
Loops
Loop statements are used to execute the block of the code repeatedly for
a specified number of times
There are three types of loops
Python for loop
Python while loop
Python nested loop
38
while Loop
Syntax :
while test_expression:
#statement(s)
While loop will execute a block of statement as long as test expression is true
39
while ..else Loop
While loop will execute a block of statement as long as test expression is true
while test:
statements
if test: break # Exit loop now, skip else if present
if test: continue # Go to top of loop now, to test1
else:
statements # Run if we didn't hit a 'break'
40
continue statement
forces the loop to continue or execute the next iteration
When the continue statement is executed in the loop, the code inside the loop following
the continue statement will be skipped and the next iteration of the loop will begin.
41
break statement
The break statement causes an immediate exit from a loop
42
Nested for and while loops
Syntax : nested for loop
for <iterator_var1> in <iterable_object1>:
for <iterator_var2> in <iterable_object2>:
#statement(s)
#statement(s)
Loop statement inside another loop statement
Syntax : nested while loop
while <exp1>:
while<exp2>
#statement(s)
#statement(s)
43
break statement
The break statement causes an immediate exit from a loop
44
Nested for and while loops
Syntax : nested for loop
for <iterator_var1> in <iterable_object1>:
for <iterator_var2> in <iterable_object2>:
#statement(s)
#statement(s)
Loop statement inside another loop statement
Syntax : nested while loop
while <exp1>:
while<exp2>
#statement(s)
#statement(s)
Sets in Python
46
Sets
Identified by curly braces
-{‘Raja’,’Ashok’,’Alok’}
Sets do not support indexing
A set an unordered collection data type that
holds an unordered collection of unique elements
set is iterable , mutable and has no duplicate
47
Description Commands
Add item to set x x.add(item)
Remove an item x.remove(item)
get length of x len(x)
Check membership in x item in x
item not in x
Pop random item from set x x.pop()
Delete all items from x x.clear()
Basic Operations on Set
48
Basic Operations on Set
A set is a python data type that holds an unordered collection of unique elements
Identified by curly braces
-{‘Raja’,’Ashok’,’Alok’}
Can only contain unique elements
Duplicates are eliminated
Sets do not support indexing
49
Frozen sets
Frozen sets in Python are immutable
objects
50
Ranges
range is another kind of immutable sequence type
ranges are also called as generators
Note that the range includes the
lower bound and excludes the
upper bound.
If we pass a single parameter to the range function, it is used as the upper bound
If we use two parameters, the first is the lower bound and the second is the upper bound.
If we use three, the third parameter is the step size.
The default lower bound is zero, and the default step size is one
Sets, Loops , & Functions
in Python
Functions in Python
What is a function ?
Why use functions ?
Types of functions ?
Functions Vs Methods
Function Signatures - Parameter Vs Arguments
User-Defined functions
The return statement
How to call a function
How to add docstrings to a function
Function arguments in python
Global Vs Local Variables
Recursive & Anonymous functions
Using main() as a function
Function as an argument
Function as return value
Map and filter() function
inner function & Decorator
Positional Vs Keyword arguments
It’s a block of code using which you want to carry out a specific task repeatedly
A function may contain zero or more than one arguments
What are functions ?
Increases readability
Eliminate redundancy
Why to use functions ?
Reduces coupling
Built-in functions, such as help() to ask for help, min() to get the minimum value,
print() to print an object to the terminal
User-Defined Functions (UDFs), which are functions that users create to help them
out;
Types of functions
Anonymous functions, which are also called lambda functions because they are not
declared with the standard def keyword
How to define user-defined functions ?
Syntax
def functionName(<parameter list>):
statement 1
statement 2
…
return expression
is used to return a value from a function
def net_sal(basic, hra, loan):
keyword
return Nsal
Here, basic, hra, and loan are called parameters of net_sal()
Also note that, basic, hra, and loan are variables ,
local to my function net_sal()
59
How to call a function ?
def net_sal(basic, hra, loan):
Gsal = basic + hra
Calling a function is Python is similar to other programming languages
Also note that, basic, hra, and loan are variables ,
local to my function net_sal()
Nsal = Gsal - loan
return Nsal
net_sal(100000,22000,5000)
Syntax
function_name(arg1, arg2,arg3)
Here, basic, hra, and loan are the arguments of net_sal function
basic, hra, and loan are passed by reference
The memory addresses of basic, hra, and loan are passed
When we call the function
60
Positional arguments
def net_sal(basic, hra, loan):
# code here
Most common way of assigning arguments to parameters:
via the order in which they are passed
When we call the function
net_sal(basic,hra, loan)
basic = 132000
hra = 22000
loan = 5000
basic = 128000
hra = 21000
loan = 6000
Its positional arguments
61
Keyword arguments
def net_sal(basic, hra, loan):
# code here
When we call the function
net_sal(basic=132000,hra = 22000, loan = 5000)
basic = 132000
hra = 22000
loan = 5000
basic = 128000
hra = 21000
loan = 6000
Its keyword arguments
Once you have defined the keyword argument , you must specify the
Keyword for all the other arguments
net_sal(132000, hra=22000, 5000)
Keyword = value
Like positional args, the no. of args and parameters must still match
62
Keyword arguments
When we call the function
net_sal(132000,hra = 22000, loan = 5000)
net_sal(132000, 22000, loan = 5000) Its keyword arguments
Can I call a function using both positional and keyword arguments ??
net_sal(132000, hra=22000,
5000)
63
Default argument values
def net_sal(basic, hra=22000, loan=5000):
# code here
When we call the function
net_sal(132000)
net_sal(basic=132000,hra = 22000)
net_sal(hra=22000, basic=132000)
When you use keyword
Argument the order doesn’t matter
64
Arguments in summary
Positional arguments must agree in order and number with the parameters
declared in the function definition
Keyword arguments must agree with declared parameters in number, but they may be
specified in arbitrary order
Default parameters allow some arguments to be omitted when function is called

More Related Content

Similar to PythonStudyMaterialSTudyMaterial.pdf

Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
DRVaibhavmeshram1
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
simenehanmut
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
Yusuf Ayuba
 
Functions2.pptx
Functions2.pptxFunctions2.pptx
Functions2.pptx
AkhilTyagi42
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
Karthik Prakash
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
Manzoor ALam
 
Lecture 08.pptx
Lecture 08.pptxLecture 08.pptx
Lecture 08.pptx
Mohammad Hassan
 
Functions_21_22.pdf
Functions_21_22.pdfFunctions_21_22.pdf
Functions_21_22.pdf
paijitk
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
Anonymous9etQKwW
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
CP-Union
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
Raghu Kumar
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
AnuragBharti27
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
AnuragBharti27
 
Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Python basics
Python basicsPython basics
Python basics
Fraboni Ec
 
Python basics
Python basicsPython basics
Python basics
James Wong
 
Python basics
Python basicsPython basics
Python basics
Tony Nguyen
 

Similar to PythonStudyMaterialSTudyMaterial.pdf (20)

Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
modul-python-all.pptx
modul-python-all.pptxmodul-python-all.pptx
modul-python-all.pptx
 
Functions2.pptx
Functions2.pptxFunctions2.pptx
Functions2.pptx
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
Lecture 08.pptx
Lecture 08.pptxLecture 08.pptx
Lecture 08.pptx
 
Functions_21_22.pdf
Functions_21_22.pdfFunctions_21_22.pdf
Functions_21_22.pdf
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
An Introduction : Python
An Introduction : PythonAn Introduction : Python
An Introduction : Python
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
 
Python Functions.pptx
Python Functions.pptxPython Functions.pptx
Python Functions.pptx
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 

Recently uploaded

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 

Recently uploaded (20)

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 

PythonStudyMaterialSTudyMaterial.pdf

  • 2. What is Python ? What you can do with it ? Why it is so popular ?
  • 3. Free and Open Source High-level programming language
  • 4. Free and Open Source High-level, multi-purpose programming language Developed by Guido Van Rossum in the late 1980s Python is an interpreter-based language
  • 5. Portable, and Extensible Python can be integrated with other popular programming technologies like C, C++, Java, ActiveX, and CORBA. Dynamic Typing Supports procedural, object-oriented, & functional programming
  • 6. What you can do with it ?
  • 9. 9
  • 10. Why it is so popular ?
  • 12. 12 What can you do with Python Develop web applications Implementing machine learning algorithms such as Scikit-learn, NLTK and Tensor flow . Computer vision – Face detection , color detection while using OpenCV and python Raspberry Pi – You can even build a robot and automate your home. PyGame – Gaming applications
  • 13.
  • 14.
  • 15. Is a reserved memory location to store values Variable Name Every value in Python has data type. 12 Computer memory Age 0 Address (index) Data Variables are used to store data, they take memory space based on the type of value we assigning to them. Age = 12
  • 16. 16 Names cannot start with a number , No spaces in the names, use underscore _ instead Special characters are not allowed as variable names income@, <>, ?, ! , (), #,$ ,% , ^, &,*,~,- + Variable Names and Naming rules Variables in Python are case sensitive It can only start with a character or an underscore
  • 17.
  • 18. 20 Name Type Description Integers int Whole numbers, such as 8 12 400 Floating Point float Numbers with a decimal point 3.3, 14.5, 500.0 Strings Str Ordered sequence of characters “hello” , “Sammy”, “2000”, “*$LL” Lists List Ordered sequence of objects [10, “hello world”, 112.4] Dictionaries dict Unordered key:value pairs {“key”:”value”} Tuples tup Ordered immutable sequence of objects (30,”Bye”, 111.32) Sets Set Unordered collection of unique objects (10,20) Booleans Bool Logical value indicating True or False Data Types
  • 20. Type conversions 22 >>> float(22//5) 4.0 >>> int(4.5) 4 >>> int(3.9) 3 >>> round(3.9) 4 >>> round(3) 3
  • 22. String formatting 24 There are multiple ways to format strings for printing variables in them Myvar= “Hello” Print(myvar + “World”) This is knowns as string interpolation
  • 23. String formatting 25 .fomat() method Myvar= “Hello” Print(myvar + “World”) This is knowns as string interpolation f-strings (formatted string literals)
  • 25. Indexing and Slicing with Strings 27
  • 26. Working with string data type 28
  • 28. 30 Booleans are two constant objects It has only two possible values Booleans are considered as numeric type in Python Booleans 1. True 2. False True == 1 False == 0 None as a Boolean value Bool(None) bool(3), bool(-3), bool(0) Nonzero integers are truth bool() method to convert a value to Boolean()
  • 29. 31 Boolean operators are those that take Boolean inputs and return Boolean results and operator can be defined in terms of ‘not’ and ‘or’ Boolean operators Boolean operators are and , not, or or operator can be defined in terms of ‘not’ and ‘and’
  • 31. Provides us with 3 types of control statements Conditional Programming Used to control the order of execution of the program based on the values and logic continue break pass
  • 32. 34 expression: It’s the condition that needs to evaluated and return a boolean (true/false)value. statement: statement is a general python code that executes if the expression returns true. Control Structures
  • 34. 36 Loops Loop statements are used to execute the block of the code repeatedly for a specified number of times There are three types of loops Python for loop Python while loop Python nested loop
  • 35. 38 while Loop Syntax : while test_expression: #statement(s) While loop will execute a block of statement as long as test expression is true
  • 36. 39 while ..else Loop While loop will execute a block of statement as long as test expression is true while test: statements if test: break # Exit loop now, skip else if present if test: continue # Go to top of loop now, to test1 else: statements # Run if we didn't hit a 'break'
  • 37. 40 continue statement forces the loop to continue or execute the next iteration When the continue statement is executed in the loop, the code inside the loop following the continue statement will be skipped and the next iteration of the loop will begin.
  • 38. 41 break statement The break statement causes an immediate exit from a loop
  • 39. 42 Nested for and while loops Syntax : nested for loop for <iterator_var1> in <iterable_object1>: for <iterator_var2> in <iterable_object2>: #statement(s) #statement(s) Loop statement inside another loop statement Syntax : nested while loop while <exp1>: while<exp2> #statement(s) #statement(s)
  • 40. 43 break statement The break statement causes an immediate exit from a loop
  • 41. 44 Nested for and while loops Syntax : nested for loop for <iterator_var1> in <iterable_object1>: for <iterator_var2> in <iterable_object2>: #statement(s) #statement(s) Loop statement inside another loop statement Syntax : nested while loop while <exp1>: while<exp2> #statement(s) #statement(s)
  • 43. 46 Sets Identified by curly braces -{‘Raja’,’Ashok’,’Alok’} Sets do not support indexing A set an unordered collection data type that holds an unordered collection of unique elements set is iterable , mutable and has no duplicate
  • 44. 47 Description Commands Add item to set x x.add(item) Remove an item x.remove(item) get length of x len(x) Check membership in x item in x item not in x Pop random item from set x x.pop() Delete all items from x x.clear() Basic Operations on Set
  • 45. 48 Basic Operations on Set A set is a python data type that holds an unordered collection of unique elements Identified by curly braces -{‘Raja’,’Ashok’,’Alok’} Can only contain unique elements Duplicates are eliminated Sets do not support indexing
  • 46. 49 Frozen sets Frozen sets in Python are immutable objects
  • 47. 50 Ranges range is another kind of immutable sequence type ranges are also called as generators Note that the range includes the lower bound and excludes the upper bound. If we pass a single parameter to the range function, it is used as the upper bound If we use two parameters, the first is the lower bound and the second is the upper bound. If we use three, the third parameter is the step size. The default lower bound is zero, and the default step size is one
  • 48. Sets, Loops , & Functions in Python
  • 50. What is a function ? Why use functions ? Types of functions ? Functions Vs Methods Function Signatures - Parameter Vs Arguments User-Defined functions The return statement How to call a function How to add docstrings to a function Function arguments in python Global Vs Local Variables Recursive & Anonymous functions Using main() as a function Function as an argument Function as return value Map and filter() function inner function & Decorator Positional Vs Keyword arguments
  • 51. It’s a block of code using which you want to carry out a specific task repeatedly A function may contain zero or more than one arguments What are functions ?
  • 52. Increases readability Eliminate redundancy Why to use functions ? Reduces coupling
  • 53. Built-in functions, such as help() to ask for help, min() to get the minimum value, print() to print an object to the terminal User-Defined Functions (UDFs), which are functions that users create to help them out; Types of functions Anonymous functions, which are also called lambda functions because they are not declared with the standard def keyword
  • 54. How to define user-defined functions ? Syntax def functionName(<parameter list>): statement 1 statement 2 … return expression is used to return a value from a function def net_sal(basic, hra, loan): keyword return Nsal Here, basic, hra, and loan are called parameters of net_sal() Also note that, basic, hra, and loan are variables , local to my function net_sal()
  • 55. 59 How to call a function ? def net_sal(basic, hra, loan): Gsal = basic + hra Calling a function is Python is similar to other programming languages Also note that, basic, hra, and loan are variables , local to my function net_sal() Nsal = Gsal - loan return Nsal net_sal(100000,22000,5000) Syntax function_name(arg1, arg2,arg3) Here, basic, hra, and loan are the arguments of net_sal function basic, hra, and loan are passed by reference The memory addresses of basic, hra, and loan are passed When we call the function
  • 56. 60 Positional arguments def net_sal(basic, hra, loan): # code here Most common way of assigning arguments to parameters: via the order in which they are passed When we call the function net_sal(basic,hra, loan) basic = 132000 hra = 22000 loan = 5000 basic = 128000 hra = 21000 loan = 6000 Its positional arguments
  • 57. 61 Keyword arguments def net_sal(basic, hra, loan): # code here When we call the function net_sal(basic=132000,hra = 22000, loan = 5000) basic = 132000 hra = 22000 loan = 5000 basic = 128000 hra = 21000 loan = 6000 Its keyword arguments Once you have defined the keyword argument , you must specify the Keyword for all the other arguments net_sal(132000, hra=22000, 5000) Keyword = value Like positional args, the no. of args and parameters must still match
  • 58. 62 Keyword arguments When we call the function net_sal(132000,hra = 22000, loan = 5000) net_sal(132000, 22000, loan = 5000) Its keyword arguments Can I call a function using both positional and keyword arguments ?? net_sal(132000, hra=22000, 5000)
  • 59. 63 Default argument values def net_sal(basic, hra=22000, loan=5000): # code here When we call the function net_sal(132000) net_sal(basic=132000,hra = 22000) net_sal(hra=22000, basic=132000) When you use keyword Argument the order doesn’t matter
  • 60. 64 Arguments in summary Positional arguments must agree in order and number with the parameters declared in the function definition Keyword arguments must agree with declared parameters in number, but they may be specified in arbitrary order Default parameters allow some arguments to be omitted when function is called