Why don't I need an else statement?

Why don’t I need to use an else statement? How is that still bringing the correct list although the index selected is bigger than length?

def double_index(lst, index):
if index < len(lst):
lst[index] = lst[index] * 2
return lst
print(double_index([3, 8, -10, 12], 10))

brings [3, 8, -10, 12]

So an else statement is only required if you wish to have 2 follow up code sections based on your conditional and then have the code continue. However since we are returning a value you can only do the if, and then break out of the function using return so the rest isn’t run.

if condition == true:
  do this
  do this
in either case do this afterwards

as compared to this, where the run this afterwards is getting skipped if we used return to leave the function.

if condition == true:
  do this
  return something
run this code afterwards