Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: kwargs | Arguments in Function
Intermediate Python: Arguments, Scopes and Decorators
course content

Contenido del Curso

Intermediate Python: Arguments, Scopes and Decorators

Intermediate Python: Arguments, Scopes and Decorators

1. Packing and Unpacking
2. Arguments in Function
3. Function as an Argument
4. Variable Scope
5. Decorators

Challenge: kwargs

Tarea

Write a Python function named create_user_profile that accepts various user attributes as keyword arguments and formats them into a user profile string.

Functionality:

  • The function should iterate over the kwargs and construct a string that lists each attribute and its value in a readable format.
  • Handle the case where no attributes are provided.

Output:

Return a string representing the user profile.

  1. Check if the kwargs dictionary is empty;
  2. Unpack each key-value pair in kwargs using a for loop;
  3. Used method items(). This is the method to iterate over both keys and values in a dictionary;
  4. Use the append method. This will add each formatted key-value pair to the profile_parts list;
  5. Call the function with keyword arguments.

Tarea

Write a Python function named create_user_profile that accepts various user attributes as keyword arguments and formats them into a user profile string.

Functionality:

  • The function should iterate over the kwargs and construct a string that lists each attribute and its value in a readable format.
  • Handle the case where no attributes are provided.

Output:

Return a string representing the user profile.

  1. Check if the kwargs dictionary is empty;
  2. Unpack each key-value pair in kwargs using a for loop;
  3. Used method items(). This is the method to iterate over both keys and values in a dictionary;
  4. Use the append method. This will add each formatted key-value pair to the profile_parts list;
  5. Call the function with keyword arguments.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 2. Capítulo 5
toggle bottom row

Challenge: kwargs

Tarea

Write a Python function named create_user_profile that accepts various user attributes as keyword arguments and formats them into a user profile string.

Functionality:

  • The function should iterate over the kwargs and construct a string that lists each attribute and its value in a readable format.
  • Handle the case where no attributes are provided.

Output:

Return a string representing the user profile.

  1. Check if the kwargs dictionary is empty;
  2. Unpack each key-value pair in kwargs using a for loop;
  3. Used method items(). This is the method to iterate over both keys and values in a dictionary;
  4. Use the append method. This will add each formatted key-value pair to the profile_parts list;
  5. Call the function with keyword arguments.

Tarea

Write a Python function named create_user_profile that accepts various user attributes as keyword arguments and formats them into a user profile string.

Functionality:

  • The function should iterate over the kwargs and construct a string that lists each attribute and its value in a readable format.
  • Handle the case where no attributes are provided.

Output:

Return a string representing the user profile.

  1. Check if the kwargs dictionary is empty;
  2. Unpack each key-value pair in kwargs using a for loop;
  3. Used method items(). This is the method to iterate over both keys and values in a dictionary;
  4. Use the append method. This will add each formatted key-value pair to the profile_parts list;
  5. Call the function with keyword arguments.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 2. Capítulo 5
toggle bottom row

Challenge: kwargs

Tarea

Write a Python function named create_user_profile that accepts various user attributes as keyword arguments and formats them into a user profile string.

Functionality:

  • The function should iterate over the kwargs and construct a string that lists each attribute and its value in a readable format.
  • Handle the case where no attributes are provided.

Output:

Return a string representing the user profile.

  1. Check if the kwargs dictionary is empty;
  2. Unpack each key-value pair in kwargs using a for loop;
  3. Used method items(). This is the method to iterate over both keys and values in a dictionary;
  4. Use the append method. This will add each formatted key-value pair to the profile_parts list;
  5. Call the function with keyword arguments.

Tarea

Write a Python function named create_user_profile that accepts various user attributes as keyword arguments and formats them into a user profile string.

Functionality:

  • The function should iterate over the kwargs and construct a string that lists each attribute and its value in a readable format.
  • Handle the case where no attributes are provided.

Output:

Return a string representing the user profile.

  1. Check if the kwargs dictionary is empty;
  2. Unpack each key-value pair in kwargs using a for loop;
  3. Used method items(). This is the method to iterate over both keys and values in a dictionary;
  4. Use the append method. This will add each formatted key-value pair to the profile_parts list;
  5. Call the function with keyword arguments.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Tarea

Write a Python function named create_user_profile that accepts various user attributes as keyword arguments and formats them into a user profile string.

Functionality:

  • The function should iterate over the kwargs and construct a string that lists each attribute and its value in a readable format.
  • Handle the case where no attributes are provided.

Output:

Return a string representing the user profile.

  1. Check if the kwargs dictionary is empty;
  2. Unpack each key-value pair in kwargs using a for loop;
  3. Used method items(). This is the method to iterate over both keys and values in a dictionary;
  4. Use the append method. This will add each formatted key-value pair to the profile_parts list;
  5. Call the function with keyword arguments.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 2. Capítulo 5
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt