KEMBAR78
function in python programming languges .pptx
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]

function in python programming languges .pptx

  • 1.
  • 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
  • 4.
  • 5.
    Defining function  deffunction_name (parameter1, parameter2) : statment1 statement2 return value to return
  • 6.
    Defining and callingfunctions Saving result in z variable
  • 7.
    Defining and callingfunctions With out saving result just print it
  • 8.
  • 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 thedifference 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, youcan 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  Writea 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  Writea 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  Writea 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]