Ravindra BagaleCourses & study guides मराठी Track your progress

Python Functions Tutorial: def, return, Arguments and lambda with Examples

Ravindra Bagale's Tip — Chala mitrano

When you copy the same code three times, it is time for a function. Today we package our logic into reusable functions. pandas apply and groupby will use them.

What you will learn in this chapter

  • Why functions save time
  • def and return
  • Parameters, default values and keyword arguments
  • Returning many values
  • Local and global variables
  • lambda for tiny functions
  • Docstrings so others understand your function

Practice data

All names, shops, banks, hospitals and amounts in this chapter are made up for learning. They are not real people or real company numbers.

Concepts in this chapter

  1. P7.1What Is a Function in Python and Why Use It
  2. P7.2How to Use return in a Python Function
  3. P7.3Python Function Arguments: Default Values and Keyword Arguments
  4. P7.4Return Multiple Values and Local Variables in Python
  5. P7.5Python lambda Functions Explained with Examples
  6. P7.6How to Write a Docstring for a Python Function