Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialaa114
1,697 PointsWhy use '=None'?
Why kenneth assinged first and last name to None?
def unpacker(first_name=None, last_name=None):
if first_name and last_name:
print("Hi {} {}".format(first_name, last_name))
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsGood question! By specifying default values for the parameters, this allows the function to be called without specifying all of the parameters. If a parameter in your code above is not specified, it will be assigned None
. Note that the print
statement can only be reached if both parameters have been specified as not None
.
>>> unpacker("FName", "LName")
Hi FName LName
>>> unpacker("FName")
>>> unpacker("FName", last_name=None)
>>>
Post back if you have more questions. Good luck!