SlideShare a Scribd company logo
2
Most read
3
Most read
10
Most read
Introduction to Advanced
Python Programming
Jagdish D. Chavan
Data Scientist| Emerging Industry Trainer|
Certified Python, Data Science Trainer| AI,ML,DL Expert
Github | Linkedin
Functional Programming
● Functional programming decomposes a problem into a set of functions.
● Ideally, Functions only take inputs and produce output, and don’t have any internal state that affects
the output produced for a given input.
● Functional techniques common to many languages : such as lambda, map, reduce.
*Note:- for more code & projects follow me on Linkedin | Github
Anonymous Functions or Lambdas
● Anonymous functions are the functions without name.
● Anonymous functions are not defined using ‘def’ keyword.
● They are defined using the keyword lambda hence also called as lambda functions.
*Note:- for more code & projects follow me on Linkedin | Github
Syntax for Lambda function.
Syntax for normal function
def function_name(parameters):
function_block
return expression
Example:- Square of Given value
code
def square(x): #declaring function
return x*x
square(9) #calling a function
Output
81
*Note:- for more code & projects follow me on Linkedin | Github
Syntax for Lambda Function
Lambda argument_list : expression
Example:- Square of Given value
Code
y = lambda x: x*x #declaring
value = y(9) #calling a function
print(value)
Output
81
Syntax for Lambda function.
*Note:- for more code & projects follow me on Linkedin | Github
Syntax :- Lambda <argument_list> : <expression>
f = lambda x: x*x
● Observe the keyword ‘lambda’. This represents that an anonymous function is being created.
● ‘X’ is argument of function followed by colon(:) representing beginning of function containing expression x*x.
● Normally, if a function returns some value, we assign that value to a variable as:
y = square(9)
● but , lambda function returns a function and hence they should to assign to function as:
f = lambda x:x*x
● Here ‘f’ is the function name to which lambda expression is assigned. Now if we call the functions f() as: value =f(5)
Properties of Lambda function.
*Note:- for more code & projects follow me on Linkedin | Github
● We can pass n number of arguments in lambda function, but only one expression is allowed.
● They return the result implicitly, hence we should not write any ‘return’ statements in the
lambda functions.
● Because a lambda functions is always represented by a function, we can pass a lambda function
to another function .
● It means we are passing a function (i.e lambda ) to another function, making processing data
very easy lambda function are generally used with functions like filter(), map(), or reduce().
Exercise no 1.
*Note:- for more code & projects follow me on Linkedin | Github
1) Write a Python Program to create a lambda function that returns a square value of given
number.
2) Write a Python Program to calculate the sum of two numbers using lambda function
3) Write a Python Program to find bigger number in two given number using Lambda Function .
Note:- for more examples and answers please do visit Advance Python Programming
Using Lambda with Filter() Function.
*Note:- for more code & projects follow me on Linkedin | Github
● The filter() function is useful to filter out the elements of a sequence depending on the result of
a function.
● We should supply a function and a sequence to the filter() function as
Syntax :-filter(function, sequence)
● function:- represent the function name that may return either True or False.
● Sequence:-represents a list, string or tuple.
● The ‘function’ is applied to every element of the ‘sequence’ and when function returns True, the
element is extracted otherwise it is ignored.
Using Lambda with Filter() Function.
*Note:- for more code & projects follow me on Linkedin | Github
Example
#write a python Program using lambda function that returns even number from the list.
lst = [10,23,45,46,70,99]
lst1 = list(filter(lambda x:(x%2==0),lst))
print(lst1)
Output
[10, 46, 70]
Using Lambda with map() Function.
*Note:- for more code & projects follow me on Linkedin | Github
● map () function acts on each element of the sequence and perhaps changes the element
● The syntax of map() function is as follow
Syntax:- map(function, sequence)
● The function performs specific operations on all the elements of the sequence and modified
element are returned which can be stored in another sequence.
Example
#write a python program using lambda function that returns squares of elements in a list.
lst = [1,2,3,4,5]
lst1 = list(map(lambda x: x*x, lst))
print(lst1)
Output
[1, 4, 9, 16, 25]
Using Lambda with map() Function.
*Note:- for more code & projects follow me on Linkedin | Github
Exercise
1) Write a Python program to find the products of elements of two different lists using lambda
function.
Note:- for more examples and answers please do visit Advance Python Programming
Using Lambda with reduce() Function.
*Note:- for more code & projects follow me on Linkedin | Github
● reduce () function reduces a sequence of elements to a single value by processing elemets
according to a function supplied.
● Syntax :- reduce(function, sequence)
Example
#write a Python program using lambda function to calculate product of elements of list
from functools import *
lst = [1,2,3,4,5]
result = reduce(lambda x,y: x*y,lst)
print(result)
Output
120

More Related Content

PDF
Python Generators
Akshar Raaj
 
PPTX
Recursion
Abdur Rehman
 
PDF
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
PPT
Introduction to ADO.NET
rchakra
 
PPTX
Functions in c++
Rokonuzzaman Rony
 
PDF
Python programming : Inheritance and polymorphism
Emertxe Information Technologies Pvt Ltd
 
PPTX
Interface in java
PhD Research Scholar
 
PPT
Php with MYSQL Database
Computer Hardware & Trouble shooting
 
Python Generators
Akshar Raaj
 
Recursion
Abdur Rehman
 
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Introduction to ADO.NET
rchakra
 
Functions in c++
Rokonuzzaman Rony
 
Python programming : Inheritance and polymorphism
Emertxe Information Technologies Pvt Ltd
 
Interface in java
PhD Research Scholar
 
Php with MYSQL Database
Computer Hardware & Trouble shooting
 

What's hot (20)

PPT
friend function(c++)
Ritika Sharma
 
PDF
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
PDF
Method overloading, recursion, passing and returning objects from method, new...
JAINAM KAPADIYA
 
PPTX
Recursion in c++
Abdul Rehman
 
PPS
Interface
kamal kotecha
 
PPT
Operating Systems - "Chapter 5 Process Synchronization"
Ra'Fat Al-Msie'deen
 
PPTX
Database Connectivity in PHP
Taha Malampatti
 
PPTX
Super keyword in java
Hitesh Kumar
 
PDF
Method Overloading In Java
CharthaGaglani
 
PDF
Java threads
Prabhakaran V M
 
PPT
FUNCTIONS IN c++ PPT
03062679929
 
PDF
itft-Decision making and branching in java
Atul Sehdev
 
PPTX
Graph representation
Tech_MX
 
PPTX
Inheritance in c++
Vishal Patil
 
PPTX
Keywords of java
Jani Harsh
 
PPTX
Design and Analysis of Algorithms
Arvind Krishnaa
 
PPT
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
PPTX
Regular expressions in Python
Sujith Kumar
 
PPTX
Templates in c++
ThamizhselviKrishnam
 
friend function(c++)
Ritika Sharma
 
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
Method overloading, recursion, passing and returning objects from method, new...
JAINAM KAPADIYA
 
Recursion in c++
Abdul Rehman
 
Interface
kamal kotecha
 
Operating Systems - "Chapter 5 Process Synchronization"
Ra'Fat Al-Msie'deen
 
Database Connectivity in PHP
Taha Malampatti
 
Super keyword in java
Hitesh Kumar
 
Method Overloading In Java
CharthaGaglani
 
Java threads
Prabhakaran V M
 
FUNCTIONS IN c++ PPT
03062679929
 
itft-Decision making and branching in java
Atul Sehdev
 
Graph representation
Tech_MX
 
Inheritance in c++
Vishal Patil
 
Keywords of java
Jani Harsh
 
Design and Analysis of Algorithms
Arvind Krishnaa
 
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
Regular expressions in Python
Sujith Kumar
 
Templates in c++
ThamizhselviKrishnam
 
Ad

Similar to Advance python programming (20)

PPTX
Advanced Programming_Basics of functional Programming.pptx
ManjishPal
 
PPTX
lambda engineering students machine learnings.pptx
mrsam3062
 
PPTX
Function in Python.pptx by Faculty at gla university in mathura uttar pradesh
bloodskullgoswami
 
PPTX
Functions in Python
Shakti Singh Rathore
 
PPTX
Python lambda.pptx
prakashvs7
 
PPT
04_python_functions.ppt You can define functions to provide the required func...
anaveenkumar4
 
PPTX
Python for Data Science function third module ppt.pptx
bmit1
 
PDF
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
 
PPTX
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
tony8553004135
 
PPTX
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
 
PPTX
Introductions to Functions in python programming.pptx
Rajtherock
 
PPTX
Python programming: Anonymous functions, String operations
Megha V
 
PPTX
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
Maulik Borsaniya
 
PPTX
functions.pptx
KavithaChekuri3
 
PPTX
Functions in advanced programming
VisnuDharsini
 
PPTX
Python Lambda Function
Md Soyaib
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PPTX
Advance Programming Slide lecture 4.pptx
mohsinfareed780
 
PPTX
JNTUK python programming python unit 3.pptx
Venkateswara Babu Ravipati
 
Advanced Programming_Basics of functional Programming.pptx
ManjishPal
 
lambda engineering students machine learnings.pptx
mrsam3062
 
Function in Python.pptx by Faculty at gla university in mathura uttar pradesh
bloodskullgoswami
 
Functions in Python
Shakti Singh Rathore
 
Python lambda.pptx
prakashvs7
 
04_python_functions.ppt You can define functions to provide the required func...
anaveenkumar4
 
Python for Data Science function third module ppt.pptx
bmit1
 
What is Python Lambda Function? Python Tutorial | Edureka
Edureka!
 
UNIT-02-pythonfunctions python function using detehdjsjehhdjejdhdjdjdjddjdhdhhd
tony8553004135
 
OOPS Object oriented Programming PPT Tutorial
amitnitpatna
 
Introductions to Functions in python programming.pptx
Rajtherock
 
Python programming: Anonymous functions, String operations
Megha V
 
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
Maulik Borsaniya
 
functions.pptx
KavithaChekuri3
 
Functions in advanced programming
VisnuDharsini
 
Python Lambda Function
Md Soyaib
 
Functions in Python Programming Language
BeulahS2
 
Advance Programming Slide lecture 4.pptx
mohsinfareed780
 
JNTUK python programming python unit 3.pptx
Venkateswara Babu Ravipati
 
Ad

Recently uploaded (20)

PPTX
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
PDF
1 Simple and Compound Interest_953c061c981ff8640f0b8e733b245589.pdf
JaexczJol060205
 
PPTX
Machine Learning Solution for Power Grid Cybersecurity with GraphWavelets
Sione Palu
 
PDF
TCP_IP for Programmers ------ slides.pdf
Souhailsouhail5
 
PDF
A Systems Thinking Approach to Algorithmic Fairness.pdf
Epistamai
 
PPTX
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
akmibrahimbd
 
PPTX
Probability systematic sampling methods.pptx
PrakashRajput19
 
PPTX
Analysis of Employee_Attrition_Presentation.pptx
AdawuRedeemer
 
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
abhinavmemories2026
 
PPTX
Economic Sector Performance Recovery.pptx
yulisbaso2020
 
PDF
Linux OS guide to know, operate. Linux Filesystem, command, users and system
Kiran Maharjan
 
PDF
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
PDF
CH1-MODEL-BUILDING-v2017.1-APR27-2017.pdf
jcc00023con
 
PPTX
1intro to AI.pptx AI components & composition
ssuserb993e5
 
PPTX
Presentation (1) (1).pptx k8hhfftuiiigff
karthikjagath2005
 
PPTX
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
PDF
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
PDF
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
PDF
AI Lect 2 Identifying AI systems, branches of AI, etc.pdf
mswindow00
 
PPTX
Lecture 1 Intro in Inferential Statistics.pptx
MiraLamuton
 
Pipeline Automatic Leak Detection for Water Distribution Systems
Sione Palu
 
1 Simple and Compound Interest_953c061c981ff8640f0b8e733b245589.pdf
JaexczJol060205
 
Machine Learning Solution for Power Grid Cybersecurity with GraphWavelets
Sione Palu
 
TCP_IP for Programmers ------ slides.pdf
Souhailsouhail5
 
A Systems Thinking Approach to Algorithmic Fairness.pdf
Epistamai
 
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
akmibrahimbd
 
Probability systematic sampling methods.pptx
PrakashRajput19
 
Analysis of Employee_Attrition_Presentation.pptx
AdawuRedeemer
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
abhinavmemories2026
 
Economic Sector Performance Recovery.pptx
yulisbaso2020
 
Linux OS guide to know, operate. Linux Filesystem, command, users and system
Kiran Maharjan
 
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
CH1-MODEL-BUILDING-v2017.1-APR27-2017.pdf
jcc00023con
 
1intro to AI.pptx AI components & composition
ssuserb993e5
 
Presentation (1) (1).pptx k8hhfftuiiigff
karthikjagath2005
 
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
Company Presentation pada Perusahaan ADB.pdf
didikfahmi
 
AI Lect 2 Identifying AI systems, branches of AI, etc.pdf
mswindow00
 
Lecture 1 Intro in Inferential Statistics.pptx
MiraLamuton
 

Advance python programming

  • 1. Introduction to Advanced Python Programming Jagdish D. Chavan Data Scientist| Emerging Industry Trainer| Certified Python, Data Science Trainer| AI,ML,DL Expert Github | Linkedin
  • 2. Functional Programming ● Functional programming decomposes a problem into a set of functions. ● Ideally, Functions only take inputs and produce output, and don’t have any internal state that affects the output produced for a given input. ● Functional techniques common to many languages : such as lambda, map, reduce. *Note:- for more code & projects follow me on Linkedin | Github
  • 3. Anonymous Functions or Lambdas ● Anonymous functions are the functions without name. ● Anonymous functions are not defined using ‘def’ keyword. ● They are defined using the keyword lambda hence also called as lambda functions. *Note:- for more code & projects follow me on Linkedin | Github
  • 4. Syntax for Lambda function. Syntax for normal function def function_name(parameters): function_block return expression Example:- Square of Given value code def square(x): #declaring function return x*x square(9) #calling a function Output 81 *Note:- for more code & projects follow me on Linkedin | Github Syntax for Lambda Function Lambda argument_list : expression Example:- Square of Given value Code y = lambda x: x*x #declaring value = y(9) #calling a function print(value) Output 81
  • 5. Syntax for Lambda function. *Note:- for more code & projects follow me on Linkedin | Github Syntax :- Lambda <argument_list> : <expression> f = lambda x: x*x ● Observe the keyword ‘lambda’. This represents that an anonymous function is being created. ● ‘X’ is argument of function followed by colon(:) representing beginning of function containing expression x*x. ● Normally, if a function returns some value, we assign that value to a variable as: y = square(9) ● but , lambda function returns a function and hence they should to assign to function as: f = lambda x:x*x ● Here ‘f’ is the function name to which lambda expression is assigned. Now if we call the functions f() as: value =f(5)
  • 6. Properties of Lambda function. *Note:- for more code & projects follow me on Linkedin | Github ● We can pass n number of arguments in lambda function, but only one expression is allowed. ● They return the result implicitly, hence we should not write any ‘return’ statements in the lambda functions. ● Because a lambda functions is always represented by a function, we can pass a lambda function to another function . ● It means we are passing a function (i.e lambda ) to another function, making processing data very easy lambda function are generally used with functions like filter(), map(), or reduce().
  • 7. Exercise no 1. *Note:- for more code & projects follow me on Linkedin | Github 1) Write a Python Program to create a lambda function that returns a square value of given number. 2) Write a Python Program to calculate the sum of two numbers using lambda function 3) Write a Python Program to find bigger number in two given number using Lambda Function . Note:- for more examples and answers please do visit Advance Python Programming
  • 8. Using Lambda with Filter() Function. *Note:- for more code & projects follow me on Linkedin | Github ● The filter() function is useful to filter out the elements of a sequence depending on the result of a function. ● We should supply a function and a sequence to the filter() function as Syntax :-filter(function, sequence) ● function:- represent the function name that may return either True or False. ● Sequence:-represents a list, string or tuple. ● The ‘function’ is applied to every element of the ‘sequence’ and when function returns True, the element is extracted otherwise it is ignored.
  • 9. Using Lambda with Filter() Function. *Note:- for more code & projects follow me on Linkedin | Github Example #write a python Program using lambda function that returns even number from the list. lst = [10,23,45,46,70,99] lst1 = list(filter(lambda x:(x%2==0),lst)) print(lst1) Output [10, 46, 70]
  • 10. Using Lambda with map() Function. *Note:- for more code & projects follow me on Linkedin | Github ● map () function acts on each element of the sequence and perhaps changes the element ● The syntax of map() function is as follow Syntax:- map(function, sequence) ● The function performs specific operations on all the elements of the sequence and modified element are returned which can be stored in another sequence. Example #write a python program using lambda function that returns squares of elements in a list. lst = [1,2,3,4,5] lst1 = list(map(lambda x: x*x, lst)) print(lst1) Output [1, 4, 9, 16, 25]
  • 11. Using Lambda with map() Function. *Note:- for more code & projects follow me on Linkedin | Github Exercise 1) Write a Python program to find the products of elements of two different lists using lambda function. Note:- for more examples and answers please do visit Advance Python Programming
  • 12. Using Lambda with reduce() Function. *Note:- for more code & projects follow me on Linkedin | Github ● reduce () function reduces a sequence of elements to a single value by processing elemets according to a function supplied. ● Syntax :- reduce(function, sequence) Example #write a Python program using lambda function to calculate product of elements of list from functools import * lst = [1,2,3,4,5] result = reduce(lambda x,y: x*y,lst) print(result) Output 120