SlideShare a Scribd company logo
1 of 17
Function
Function in math
 F(X)=X +4X-3
2
X 5 4 2 1 0
F(X) 32 29 9 2 -3
Function in python
 In Python, a function is a block of organized, reusable code that
performs a specific task. It takes one or more input parameters,
performs some operations, and returns a value or set of values.
 Some benefit of function :
 Simplify code. More readable.​
 Reuse. Once written, use again
Function in python
input
value
parameters input
output
Defining function
 def function_name (parameter1, parameter2) :
statment1
statement2
return value to return
Defining and calling functions
Saving result in z variable
Defining and calling functions
With out saving result just print it
Calling function many time
 By default, a function must be called with the correct number of
arguments. Meaning that if your function expects 2 arguments, you have
to call the function with 2 arguments, not more, and not less.
What is the difference between
argument and parameter ?
 a parameter refers to the variable name that is used in the
function definition, which represents a value that needs to be
passed into the function when it is called.
 An argument, on the other hand, refers to the actual value that is
passed to the function when it is called.
In this example, name is a parameter of the greet() function.
When the function is called with the argument "Rund", the
value of “Rund" is passed to the parameter name. The function
then prints the greeting "Hello, Rund!".
In summary, parameters are used in function definitions to
represent input values, while arguments are the actual values
that are passed to a function when it is called.
In Python, you can assign a default value to a function
parameter. This means that if the function is called without a
corresponding argument for that parameter, the default value
will be used instead.
In this code, the info() function takes two parameters name and age.
When the function is called on the last line with age=19 and
name="Ahmed", the arguments are passed to the function in a named
order. This means that the age argument is assigned to the age
parameter, and the name argument is assigned to the name parameter.
The function then returns a string that concatenates the name and age
values, separated by a colon and a newline character. Finally, this
string is printed to the console using the print() function.
Task 1
 Write a Python function that accepts a string and counts the number of upper and
lower case letters.
Sample String : 'The quick Brow Fox'
Expected Output :
No. of Upper case characters : 3
No. of Lower case Characters : 12
 Write a Python program to print the even numbers from a given list.
Sample List : [1, 2, 3, 4, 5, 6, 7, 8, 9]
Expected Result : [2, 4, 6, 8]
Task 2
 Write a Python function that takes a list and returns a new list with distinct
elements from the first list.
Sample List : [1,2,3,3,3,3,4,5]
Unique List : [1, 2, 3, 4, 5]
Task 3
 Write a Python program to print the even numbers from a given list.
Sample List : [1, 2, 3, 4, 5, 6, 7, 8, 9]
Expected Result : [2, 4, 6, 8]

More Related Content

Similar to function in python programming languges .pptx

Similar to function in python programming languges .pptx (20)

Amit user defined functions xi (2)
Amit  user defined functions xi (2)Amit  user defined functions xi (2)
Amit user defined functions xi (2)
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
functions- best.pdf
functions- best.pdffunctions- best.pdf
functions- best.pdf
 
Fundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programmingFundamental of programming Fundamental of programming
Fundamental of programming Fundamental of programming
 
Python functions
Python   functionsPython   functions
Python functions
 
Python Function.pdf
Python Function.pdfPython Function.pdf
Python Function.pdf
 
Python programming variables and comment
Python programming variables and commentPython programming variables and comment
Python programming variables and comment
 
Python_Unit_2.pdf
Python_Unit_2.pdfPython_Unit_2.pdf
Python_Unit_2.pdf
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptxUnit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
 
functioninpython-1.pptx
functioninpython-1.pptxfunctioninpython-1.pptx
functioninpython-1.pptx
 
Python programming - Functions and list and tuples
Python programming - Functions and list and tuplesPython programming - Functions and list and tuples
Python programming - Functions and list and tuples
 
PYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptxPYTHON-PROGRAMMING-UNIT-II (1).pptx
PYTHON-PROGRAMMING-UNIT-II (1).pptx
 
Chapter 1.ppt
Chapter 1.pptChapter 1.ppt
Chapter 1.ppt
 
Function
FunctionFunction
Function
 
Functions.docx
Functions.docxFunctions.docx
Functions.docx
 
Pro
ProPro
Pro
 
Python Lecture 4
Python Lecture 4Python Lecture 4
Python Lecture 4
 
functions modules and exceptions handlings.ppt
functions modules and exceptions handlings.pptfunctions modules and exceptions handlings.ppt
functions modules and exceptions handlings.ppt
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

function in python programming languges .pptx

  • 2. Function in math  F(X)=X +4X-3 2 X 5 4 2 1 0 F(X) 32 29 9 2 -3
  • 3. Function in python  In Python, a function is a block of organized, reusable code that performs a specific task. It takes one or more input parameters, performs some operations, and returns a value or set of values.  Some benefit of function :  Simplify code. More readable.​  Reuse. Once written, use again
  • 5. Defining function  def function_name (parameter1, parameter2) : statment1 statement2 return value to return
  • 6. Defining and calling functions Saving result in z variable
  • 7. Defining and calling functions With out saving result just print it
  • 9.  By default, a function must be called with the correct number of arguments. Meaning that if your function expects 2 arguments, you have to call the function with 2 arguments, not more, and not less.
  • 10.
  • 11. What is the difference between argument and parameter ?  a parameter refers to the variable name that is used in the function definition, which represents a value that needs to be passed into the function when it is called.  An argument, on the other hand, refers to the actual value that is passed to the function when it is called.
  • 12. In this example, name is a parameter of the greet() function. When the function is called with the argument "Rund", the value of “Rund" is passed to the parameter name. The function then prints the greeting "Hello, Rund!". In summary, parameters are used in function definitions to represent input values, while arguments are the actual values that are passed to a function when it is called.
  • 13. In Python, you can assign a default value to a function parameter. This means that if the function is called without a corresponding argument for that parameter, the default value will be used instead.
  • 14. In this code, the info() function takes two parameters name and age. When the function is called on the last line with age=19 and name="Ahmed", the arguments are passed to the function in a named order. This means that the age argument is assigned to the age parameter, and the name argument is assigned to the name parameter. The function then returns a string that concatenates the name and age values, separated by a colon and a newline character. Finally, this string is printed to the console using the print() function.
  • 15. Task 1  Write a Python function that accepts a string and counts the number of upper and lower case letters. Sample String : 'The quick Brow Fox' Expected Output : No. of Upper case characters : 3 No. of Lower case Characters : 12  Write a Python program to print the even numbers from a given list. Sample List : [1, 2, 3, 4, 5, 6, 7, 8, 9] Expected Result : [2, 4, 6, 8]
  • 16. Task 2  Write a Python function that takes a list and returns a new list with distinct elements from the first list. Sample List : [1,2,3,3,3,3,4,5] Unique List : [1, 2, 3, 4, 5]
  • 17. Task 3  Write a Python program to print the even numbers from a given list. Sample List : [1, 2, 3, 4, 5, 6, 7, 8, 9] Expected Result : [2, 4, 6, 8]