All Check in Python

Level 256 keystrokes

This checks if all elements satisfy a condition. The all() function returns True if all elements in the iterable are truthy.

Python code

# Create a list of even numbers
1nums = [2, 4, 6, 8]
# all() checks if all elements satisfy the condition
# n % 2 == 0 is True for every number here, so it prints True
2print(all(n % 2 == 0 for n in nums))

Output

True
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • ,× 3
  • =× 3
  • (× 2
  • )× 2
  • [× 1
  • ]× 1
  • %× 1

More Python examples at level 2

← Python typing practice