LU05.L05 - **kwargs zu Liste

main.py
def active_settings(**kwargs):
        """
        Returns a list of settings that are set to True.
 
        Parameters:
            **kwargs: Variable number of keyword arguments representing settings.
 
        Returns:
            list: A list containing the names of the settings that are set to True.
        """
        active = [key for key, value in kwargs.items() if value is True]
        return active
 
 
if __name__ == '__main__':
    # Teste deine Funktion
    print(active_settings(wifi=True, bluetooth=False, gps=True))  # Erwarteter Output: "[wifi, gps]"
  • modul/m323/learningunits/lu05/loesungen/kwargs2.txt
  • Zuletzt geändert: 2024/03/28 14:07
  • von 127.0.0.1