Good Code
The good version treats None as the missing case and preserves an intentionally empty nickname.
Lesson 02
Distinguish missing values from valid falsy values such as empty strings, zero, and empty collections.
def display_name(user):
if user.nickname is None:
return user.full_name
return user.nicknamedef display_name(user):
if user.nickname:
return user.nickname
return user.full_nameThe good version treats None as the missing case and preserves an intentionally empty nickname.
The bad version treats every falsy value as missing. Empty strings, zero, empty lists, and False can accidentally take the fallback path.