Python Functions for Efficient Programming

programming in python n.w
1 / 147
Embed
Share

Dive into the world of Python functions with Mrs. C. Shyamaladevi M.C.A., M.Phil., B.Ed., Assistant Professor at Shrimati Indira Gandhi College, Trichy-2. Learn about the concept of functions, types of functions, advantages they offer, and how to define and use them effectively in your programs. Enhance code reusability, modularity, and application design with Python functions.

  • Python functions
  • Mrs. C. Shyamaladevi
  • Programming concepts
  • Modularity
  • Code reusability

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. PROGRAMMING IN PYTHON PYTHON FUNCTION Mrs. C.SHYAMALADEVI M.C.A., M.Phil., B.Ed., ASSISTANT PROFESSOR, DEPARTMENT OF COMPUTER SCIENCE, SHRIMATI INDIRA GANDHI COLLEGE, TRICHY-2.

  2. Understand the concept of function and their types. Know the difference between User defined and Built in functions. Know how to call a function. Understand arguments. Know Anonymous functions. Know Mathematical some String functions. the function and

  3. Functions are named blocks of code that are designed to do specific job. When you want to perform a particular task that you have defined in a function, you call the name of the function responsible for it. If you need to perform that task multiple times throughout your program, you don t need to type all the code for the same task again and again; you just call the function dedicated to handling that task, and the call tells Python to run the code inside the function. You ll find that using functions makes your programs easier to write, read, test, and fix errors.

  4. Advantages of functions are It avoids repetition and makes high degree of code reusing. It provides modularity application. better your for

  5. Types of Functions

  6. Defining Functions

  7. Functions must be defined, to create and use certain functionality. There are many built-in functions that comes with the language python (for instance, the print() function), but you can also define your own function. When defining functions there are multiple things that need to be noted;

  8. syntax

  9. Block

  10. Nested block

  11. EXAMPLE

  12. EXAMPLE

  13. Advantages of User-defined Functions

  14. Calling function EXAMPLE

  15. EXAMPLE

  16. Passing Parameters in Functions

  17. EXAMPLE

  18. The above code assigns the width and height values to the parameters w and h. These parameters are used in the creation of the function area . When you call the above function, it returns the product of width and height as output. The value of 3 and 5 are passed to w and h respectively, the function will return 15 as output.

  19. EXAMPLE

  20. Function Arguments

  21. Required Arguments

  22. Wrong code

  23. Correct code

  24. Keyword Arguments

  25. Correct code

  26. Wrong code

  27. Correct code

  28. Default Arguments

  29. EXAMPLE

  30. EXAMPLE

  31. Variable- Length Arguments

  32. EXAMPLE

  33. Syntax

  34. EXAMPLE

  35. EXAMPLE: def printnos (*nos): for n in nos: print(n) return # now invoking the printnos() function print ("Printing two values") printnos (1,2) print ('Printing three values') printnos (10,20,30)

  36. OUTPUT: Printing two values 1 2 Printing three values 10 20 30

  37. EXAMPLE

More Related Content