ovunctuzel ovunctuzel - 1 month ago 5
Python Question

Parameter defaults using other parameters in python

Is it possible to do something like this in Python?

def func(list, l = len(list)):
print list, l

Answer

This is usually how it is done

def func(list, l = None):
    if l is None:
        l = len(list)
    print list, l

As a side note, avoid using built-in type/function names as your variable names(like list here)

Comments