SlideShare a Scribd company logo
3
Most read
7
Most read
9
Most read
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.
function in python programming languges .pptx
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

DOC
Functions
PDF
Python lambda functions with filter, map & reduce function
PPTX
functions.pptx
PPTX
Lecture 08.pptx
PPTX
Functions in Python Programming Language
PDF
Cpp functions
PPTX
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
PPTX
Python Functions.pptx
Functions
Python lambda functions with filter, map & reduce function
functions.pptx
Lecture 08.pptx
Functions in Python Programming Language
Cpp functions
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
Python Functions.pptx

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

PPTX
Amit user defined functions xi (2)
PPT
Lecture 4
PPTX
JNTUK python programming python unit 3.pptx
PDF
Unit 1-Part-5-Functions and Set Operations.pdf
PPTX
Functions in C++
PDF
functions- best.pdf
PPT
Py-Slides-3 difficultpythoncoursefforbeginners.ppt
PPTX
Fundamental of programming Fundamental of programming
PPT
Powerpoint presentation for Python Functions
PDF
Python functions
PDF
Python Function.pdf
PPT
Python programming variables and comment
PDF
Python_Unit_2.pdf
PDF
Advanced Web Technology ass.pdf
PPTX
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
PPTX
functioninpython-1.pptx
PPTX
Python programming - Functions and list and tuples
PPTX
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
PPTX
PYTHON-PROGRAMMING-UNIT-II (1).pptx
PDF
programlama fonksiyonlar c++ hjhjghjv jg
Amit user defined functions xi (2)
Lecture 4
JNTUK python programming python unit 3.pptx
Unit 1-Part-5-Functions and Set Operations.pdf
Functions in C++
functions- best.pdf
Py-Slides-3 difficultpythoncoursefforbeginners.ppt
Fundamental of programming Fundamental of programming
Powerpoint presentation for Python Functions
Python functions
Python Function.pdf
Python programming variables and comment
Python_Unit_2.pdf
Advanced Web Technology ass.pdf
Unit_5Functionspptx__2022_12_27_10_47_17 (1).pptx
functioninpython-1.pptx
Python programming - Functions and list and tuples
PYTHON-PROGRAMMING-UNIT-II.pptx gijtgjjgg jufgiju yrguhft hfgjutt jgg
PYTHON-PROGRAMMING-UNIT-II (1).pptx
programlama fonksiyonlar c++ hjhjghjv jg
Ad

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Cloud computing and distributed systems.
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Machine learning based COVID-19 study performance prediction
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 3 Spatial Domain Image Processing.pdf
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Cloud computing and distributed systems.
Programs and apps: productivity, graphics, security and other tools
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Machine learning based COVID-19 study performance prediction
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Unlocking AI with Model Context Protocol (MCP)
Ad

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.
  • 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]