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.
Ravindra Bagale's Tip – चला मित्रांनो
एकच code तीनदा copy करावा लागला की function बनवायची वेळ आली. आज आपलं logic reusable functions मध्ये बांधू. pandas apply आणि groupby हेच वापरतील.
Ravindra Bagale's Tip – चलो दोस्तों
एक ही code तीन बार copy करना पड़े तो function बनाने का समय है. आज अपना logic reusable functions में बाँधेंगे. pandas apply और groupby इन्हीं को इस्तेमाल करेंगे.
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
- P7.1What Is a Function in Python and Why Use It
- P7.2How to Use return in a Python Function
- P7.3Python Function Arguments: Default Values and Keyword Arguments
- P7.4Return Multiple Values and Local Variables in Python
- P7.5Python lambda Functions Explained with Examples
- P7.6How to Write a Docstring for a Python Function