How to check if all elements in a Python iterable are True
Python tip:
You can use all() to check if all elements in an iterable are
True
:def class_completed(exams): if all(exams): print("You've passed all the exams.") else: print("You didn't pass all of the exams.") student_that_passed = [True, True, True, True] student_that_failed = [True, True, False, True] class_completed(student_that_passed) # -> You've passed all the exams. class_completed(student_that_failed) # -> You didn't pass all of the exams.