Function in Python are First- Class Objects. This means that they can be passed around and used just like any other data types. In Shorthand it’s also known as “First-class function”
Some of the characteristics of First Class Object Objects ?
- Created at runtime
- Assigned to a variable or element in a data structure
- Passed as an arguments to a function
- Returned as the result of a function
Integers, Strings and Dictionaries are other examples of first- class objects in Python.
>>> def factorial(n):
In The above example we created a function at the runtime, doc is one of several attribute of the function objects, and factorial is an instance of function class
fact = factorial
We can assign it a variable fact and call it through that name
In the above example we passed it to the map and it also returns a function as result, Which produces a below result when passed to list
Another example is the sorted built-in function: an optional key arguments lets you provide a function to be applied to each item for sorting.
'Ankur', 'Anand', 'Sam', 'John', 'KK', 'I']name = [
Custom Reverse Function used for Sorting.