else part reads from a list.
def first_word(line):
try:
words = line.split()
except AttributeError:
return "no text"
else:
return words[0]
for x in (None, " "):
try:
print(first_word(x), end=" ")
except IndexError:
print("empty")
What does the program print?Log in to join the discussion.
Loading…