How does this function definition work in python?

I am new to Python with a Java background. I found the following function definition

def S(seq,i=0):
    print i
    if i==len(seq): 
        return 0    
    return S(seq,i+1)+seq[i]

What exactly is doing i=0here, is it reinitialized to 0 every time? As I notice that the value of i is increasing.

+3
source share
1 answer

It provides a default value for the second argument.

A function can be called with one or two arguments. If it calls one, the second argument iis zero by default.

+8
source

All Articles