Nested Functions and Tuple Return in Python

  • Share this:

Code introduction


This function defines three nested functions, where _foo() returns a tuple containing two nested functions _bar() and _baz(). Then it calls this tuple with three arguments.


Technology Stack : Functions, Nested functions, Tuple

Code Type : Function

Code Difficulty : Intermediate


                
                    
def aaaa(arg1, arg2, arg3):
    def _bar():
        return "bar"
    
    def _baz():
        return "baz"
    
    def _foo():
        return _bar(), _baz()
    
    return _foo()(arg1, arg2, arg3)