DEV Community

ishwar kokkili
ishwar kokkili

Posted on

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)