DEV Community

ishwar kokkili
ishwar kokkili

Posted on

4 3

Recursion - Own Power function

In this post I'm going to write my own power function in python which will perform like pow(x,n) in Py3

# Power function using recursion -> 

def power(num,exp):
    if exp==1: 
        return num 
    return num*power(num,exp-1)

print(f"The value is {power(5,3)})

Enter fullscreen mode Exit fullscreen mode

output -
The value is 125

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay