I am learning 8.6. bisect — Array bisection algorithm,
bisect.bisect_left(a, x, lo=0, hi=len(a))
has default values of lo=0, hi=len(a)
,
When I checked the source code and found that hi=len(a)
is not set as default directly,
def bisect_right(a, x, lo=0, hi=None):
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(a)
while lo < hi:
mid = (lo+hi)//2
if x < a[mid]:
hi = mid
else:
lo = mid+1
return lo
It's achieved by a if check None.
What's the benefit do extra checking than set it as default straightly?