SlideShare a Scribd company logo
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

What's hot

Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
Anoop Thomas Mathew
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)
IoT Code Lab
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
HalaiHansaika
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
kavitha muneeshwaran
 
C function
C functionC function
C function
thirumalaikumar3
 
Functions
FunctionsFunctions
Functions
Pragnavi Erva
 
C++ Function
C++ FunctionC++ Function
C++ Function
Hajar
 
Function in c
Function in cFunction in c
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
Sampath Kumar
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 
Function in c program
Function in c programFunction in c program
Function in c program
CGC Technical campus,Mohali
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
NUST Stuff
 
Function C++
Function C++ Function C++
Function C++
Shahzad Afridi
 
Function in c
Function in cFunction in c
Function in c
Raj Tandukar
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
Dheeraj Kataria
 
F# 101
F# 101F# 101
F# 101
Chris Alcock
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
DhivyaSubramaniyam
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 

What's hot (20)

Thinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in PythonThinking in Functions: Functional Programming in Python
Thinking in Functions: Functional Programming in Python
 
Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)Chapter 1 Basic Programming (Python Programming Lecture)
Chapter 1 Basic Programming (Python Programming Lecture)
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
C function
C functionC function
C function
 
Functions
FunctionsFunctions
Functions
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Function in c
Function in cFunction in c
Function in c
 
Functionincprogram
FunctionincprogramFunctionincprogram
Functionincprogram
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
Function C++
Function C++ Function C++
Function C++
 
Function in c
Function in cFunction in c
Function in c
 
C++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIAC++ functions presentation by DHEERAJ KATARIA
C++ functions presentation by DHEERAJ KATARIA
 
F# 101
F# 101F# 101
F# 101
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 

Similar to Advance python programming

Python lambda.pptx
Python lambda.pptxPython lambda.pptx
Python lambda.pptx
prakashvs7
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Shakti Singh Rathore
 
Scala qq
Scala qqScala qq
Scala qq
羽祈 張
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
manikanta361
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
KavithaChekuri3
 
Dev Concepts: Functional Programming
Dev Concepts: Functional ProgrammingDev Concepts: Functional Programming
Dev Concepts: Functional Programming
Svetlin Nakov
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
Geison Goes
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
KarthickT28
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
SaraswathiTAsstProfI
 
Functional programming
Functional programmingFunctional programming
Functional programming
Lhouceine OUHAMZA
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
Angelo Corsaro
 
Java 8
Java 8Java 8
Java 8
vilniusjug
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdf
SudhanshiBakre1
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
Jeevan Raj
 
Ninth session
Ninth sessionNinth session
Ninth session
AliMohammad155
 
Python functions
Python functionsPython functions
Python functions
Prof. Dr. K. Adisesha
 
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
Anil Sharma
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdf
alaparthi
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
Indrajit Das
 
Lecture1
Lecture1Lecture1

Similar to Advance python programming (20)

Python lambda.pptx
Python lambda.pptxPython lambda.pptx
Python lambda.pptx
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Scala qq
Scala qqScala qq
Scala qq
 
Inroduction to r
Inroduction to rInroduction to r
Inroduction to r
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
 
Dev Concepts: Functional Programming
Dev Concepts: Functional ProgrammingDev Concepts: Functional Programming
Dev Concepts: Functional Programming
 
Python functional programming
Python functional programmingPython functional programming
Python functional programming
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
3. functions modules_programs (1)
3. functions modules_programs (1)3. functions modules_programs (1)
3. functions modules_programs (1)
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Programming in Scala - Lecture Two
Programming in Scala - Lecture TwoProgramming in Scala - Lecture Two
Programming in Scala - Lecture Two
 
Java 8
Java 8Java 8
Java 8
 
Dive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdfDive into Python Functions Fundamental Concepts.pdf
Dive into Python Functions Fundamental Concepts.pdf
 
C programming language working with functions 1
C programming language working with functions 1C programming language working with functions 1
C programming language working with functions 1
 
Ninth session
Ninth sessionNinth session
Ninth session
 
Python functions
Python functionsPython functions
Python functions
 
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
tutorials-c-sharp_understanding-generic-anonymous-methods-and-lambda-expressi...
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdf
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
 
Lecture1
Lecture1Lecture1
Lecture1
 

Recently uploaded

一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
hyfjgavov
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
1tyxnjpia
 
Digital Marketing Performance Marketing Sample .pdf
Digital Marketing Performance Marketing  Sample .pdfDigital Marketing Performance Marketing  Sample .pdf
Digital Marketing Performance Marketing Sample .pdf
Vineet
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
dataschool1
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
Vietnam Cotton & Spinning Association
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
nyvan3
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
mkkikqvo
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
uevausa
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
ihavuls
 
Data Scientist Machine Learning Profiles .pdf
Data Scientist Machine Learning  Profiles .pdfData Scientist Machine Learning  Profiles .pdf
Data Scientist Machine Learning Profiles .pdf
Vineet
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
Vineet
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
bmucuha
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
hqfek
 
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
osoyvvf
 
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
asyed10
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
vasanthatpuram
 
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative ClassifiersML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
MastanaihnaiduYasam
 
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
yuvarajkumar334
 
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Marlon Dumas
 

Recently uploaded (20)

一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
一比一原版兰加拉学院毕业证(Langara毕业证书)学历如何办理
 
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
一比一原版(Sheffield毕业证书)谢菲尔德大学毕业证如何办理
 
Digital Marketing Performance Marketing Sample .pdf
Digital Marketing Performance Marketing  Sample .pdfDigital Marketing Performance Marketing  Sample .pdf
Digital Marketing Performance Marketing Sample .pdf
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics May 2024
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
 
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
Data Scientist Machine Learning Profiles .pdf
Data Scientist Machine Learning  Profiles .pdfData Scientist Machine Learning  Profiles .pdf
Data Scientist Machine Learning Profiles .pdf
 
Sample Devops SRE Product Companies .pdf
Sample Devops SRE  Product Companies .pdfSample Devops SRE  Product Companies .pdf
Sample Devops SRE Product Companies .pdf
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
一比一原版爱尔兰都柏林大学毕业证(本硕)ucd学位证书如何办理
 
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
一比一原版(uom毕业证书)曼彻斯特大学毕业证如何办理
 
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
一比一原版美国帕森斯设计学院毕业证(parsons毕业证书)如何办理
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
 
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative ClassifiersML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
ML-PPT-UNIT-2 Generative Classifiers Discriminative Classifiers
 
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCAModule 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
Module 1 ppt BIG DATA ANALYTICS NOTES FOR MCA
 
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
Discovering Digital Process Twins for What-if Analysis: a Process Mining Appr...
 

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