Functions in Python are first-class objects. First-class objects in a language are handled uniformly throughout. They may be stored in data structures, passed as arguments, or used in control structures.
Properties of first-class functions:
- A function is an instance of the Object type.
- You can store the function in a variable.
- You can pass the function as a parameter to another function.
- You can return the function from a function.
- You can store them in data structures such as hash tables, lists, …
Example 1: Functions without arguments
In this example, the first method is A() and the second method is B(). A() method returns the B() method that is kept as an object with name returned_function and will be used for calling the second method.
Inside the method A. Inside the method B.
Example 2: Functions with arguments
In this example, the first method is A() and the second method is B(). Here A() method is called which returns the B() method i.e; executes both the functions.
Hello and Good Morning.
Example 3: Functions with lambda
In this example, the first method is A() and the second method is unnamed i.e; with lambda. A() method returns the lambda statement method that is kept as an object with the name returned_function and will be used for calling the second method.
<function A.<locals>.<lambda> at 0x7f65d8e17158> 21
- Returning Multiple Values in Python
- Python | Returning index of a sorted list
- Python - Call function from another function
- Wand function() function in Python
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Sort Python Dictionaries by Key or Value
- Python | Merge Python key values to list
- Reading Python File-Like Objects from C | Python
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- MySQL-Connector-Python module in Python
- Python - Read blob object in python using wand library
- Python | PRAW - Python Reddit API Wrapper
- twitter-text-python (ttp) module - Python
- Reusable piece of python functionality for wrapping arbitrary blocks of code : Python Context Managers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.