Skip to Content
Learn Python by Building Data Science Applications
book

Learn Python by Building Data Science Applications

by Philipp Kats, David Katz
August 2019
Beginner
482 pages
12h 56m
English
Packt Publishing
Content preview from Learn Python by Building Data Science Applications

Logical operators

There are four logical operators that work specifically on Boolean values:

  • !—the NOT keyword (inverse of the resulting value):
>>> not (5 > 4)False
Jupyter interprets cells with an exclamation mark at the beginning as Terminal commands, so we can't use it there.
  • |—the OR keyword (one or another, or both the values):
>>> (5 > 4) | (6 < 5)True
  • &—the AND keyword (one and another value):
>>> (5 > 4) & (6 < 5)False
  • ^—the XOR keyword (either one or another, but not both of the values):
>>> (5 > 4) ^ (5 < 6)False

The following are built-in functions that work on Boolean arrays:

  • all(): Will return true only if all elements are True
  • any(): Will return true if at least one element is True
Python has strong typing—it does ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for Data Science

Python for Data Science

Yuli Vasiliev
Introduction to Machine Learning with Python

Introduction to Machine Learning with Python

Andreas C. Müller, Sarah Guido

Publisher Resources

ISBN: 9781789535365Supplemental Content