Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The second case is preferable if numbers is an Optional[List], which is usually the case when passing lists around as arguments.

  def custom_sum(numbers: Optional[List[int]] = None) -> int:
    if not numbers:
      ## something

    return sum(numbers)
This can handle both cases - if numbers is None, or numbers is []


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: