-
Notifications
You must be signed in to change notification settings - Fork 2
Python Function All
all()
is a built-in function in Python 3, to check if all items of an iterable is True
. It takes one argument, iterable
.
The iterable
argument is the collection whose all entries are to be checked. It can typically be a list
, str
, dict
, tuple
etc.
The return value would be a boolean. If and only if all entries of iterable are True
, it returns True
. This function essentially performs a Boolean AND
operation over all elements.
If even one of them is not True
, it would return False
.
The all()
operation is equivalent to (not internally implemented exactly like this)
def all(iterable):
for element in iterable:
if not element:
return False
return True
print(all([6, 7])) #=> True
print(all([6, 7, None])) #=> False Because this has None
print(all([0, 6, 7])) #=> False Because this has zero
print(all([9, 8, [1, 2]])) #=> True
print(all([9, 8, []])) #=> False Because it has []
print(all([9, 8, [1, 2, []]])) #=> True
print(all([9, 8, {}])) #=> False Because it has {}
print(all([9, 8, {'engine': 'Gcloud'}])) #=> True
🚀 Run Code
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links