Contenu du cours
Tutoriel sur les Boucles en Python
Tutoriel sur les Boucles en Python
4. Compréhensions de Listes et de Dictionnaires
L'Instruction Else dans une Boucle For
travel_list = ['Monako', 'Luxemburg', 'Liverpool', 'Barcelona', 'Munchen'] # Printing all destinations for city in travel_list: print(city) else: print('All destinations have been listed.')
travel_list = ['Monako', 'Luxemburg', 'Liverpool', 'Barcelona', 'Munchen'] # Searching for a specific city for city in travel_list: print(city) if city == 'Barcelona': break else: print('All destinations have been listed.')
travel_list = ['Monako', 'Luxemburg', 'Liverpool', 'Barcelona', 'Munchen'] # Checking if a city is NOT in the list search_city = 'Paris' if search_city not in travel_list: print(search_city, 'is not in the travel list.') else: print(search_city, 'is in the travel list.')
Tout était clair ?
Merci pour vos commentaires !
Section 1. Chapitre 5