Skip to content

Instantly share code, notes, and snippets.

@bbelderbos
Created August 9, 2023 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbelderbos/2e6e42cf7d34d718e353442836399b7d to your computer and use it in GitHub Desktop.
Save bbelderbos/2e6e42cf7d34d718e353442836399b7d to your computer and use it in GitHub Desktop.
# ok
def create_person(*args):
first_name, last_name, age = args
return {
'First Name': first_name,
'Last Name': last_name,
'Age': age
}
# Caller assumes the order: first name, last name, age.
person = create_person('John', 'Doe', 30)
print(person) # Outputs: {'First Name': 'John', 'Last Name': 'Doe', 'Age': 30}
# not ok
def create_person(*args):
# The order has changed to: age, first name, last name.
age, first_name, last_name = args
return {
'First Name': first_name,
'Last Name': last_name,
'Age': age
}
# Caller still assumes the old order: first name, last name, age.
person = create_person('John', 'Doe', 30)
print(person) # Outputs: {'First Name': 'Doe', 'Last Name': 30, 'Age': 'John'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment