Sitemap
Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Member-only story

The all() Function in Python

3 min readNov 21, 2022

--

Photo by Christian Wiediger on Unsplash

satisfying all conditions

Let’s say that there’s a job posting for a data science position. This position requires a candidate to meet all of the following criteria: at least 10 years of SQL experience, 12 years of machine learning experience, and 8 years of statistical analysis experience.

and operator

We can write a function that takes in the years of experience a candidate has, and checks whether that candidate satisfies all the requirements by returning True or False, using the familiar and operator as follows:

def is_qualified(sql, ml, stats):
if (sql >= 10) and (ml >= 12) and (stats >= 8):
return True
else:
return False

The above function uses the and operator to check if all conditions, or operands, are True. If all the expressions evaluate to True, the and operator will return True.

So if a candidate has 11 years of SQL experience, 12 years of machine learning experience, and 9 years of statistical analysis experience, the function will return True:

is_qualified(11, 12, 9)
# True

--

--

Luay Matalka
Luay Matalka

Written by Luay Matalka

Lead Machine Learning Engineer, specializing in MLOps, with a passion for teaching.