X Tutup
Skip to content

Latest commit

 

History

History
56 lines (44 loc) · 1.84 KB

File metadata and controls

56 lines (44 loc) · 1.84 KB
title Python all() built-in function - Python Cheatsheet
description Return True if all elements of the iterable are true (or if the iterable is empty).
Python all() built-in function From the Python 3 documentation Return True if all elements of the iterable are true (or if the iterable is empty).

Introduction

The all() function in Python is a built-in function that checks if all elements in an iterable are True. It returns True if every element evaluates to true, or if the iterable is empty. This is useful for validating conditions across a collection of items, such as checking if all numbers in a list are positive or if all required fields in a form are filled.

Examples

# All values are truthy
all([1, 2, 3])

# Contains a falsy value (0)
all([1, 0, 3])

# Contains a falsy value (empty string)
all(['a', '', 'c'])

# An empty iterable is considered True
all([])
True
False
False
True

Relevant links

  • Cheatsheet: Control Flow
  • Cheatsheet: Comprehensions
  • Blog: Python Data Types
  • any()
  • bool()
  • list()
  • tuple()
  • set()
  • dict()
X Tutup