简体   繁体   中英

Give an optional parameter a default value that depends on another parameter in Python

My question is rather simple : is there a more pythonic way of doing this?

def f(array, start=0, end=None):
    if not end:
        end = len(array)
    (...)

Because using f(array, start=0, end=len(array) won't work.

Not really. One nitpick:

def f(array, start=0, end=None):
    if end is None:
        end = len(array)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM