Last answered:

08 Apr 2024

Posted on:

31 Mar 2024

0

Resolved: define a function in the other function

Here we call one function while defining another function can we define one function in other function?

1 answers ( 1 marked as helpful)
Instructor
Posted on:

08 Apr 2024

0

Hi Meenakshi!

Thanks for reaching out!

Yes, in Python, you can define one function inside another function. This concept is known as nested functions or inner functions.

For instance, in this case that could be:
def m_by_3(x):
    def plus_five(y):
        return y + 5
    return plus_five(x) * 3

m_by_3(5)

Hope this helps.

Best,

Ivan

Submit an answer