Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 24353

Python Morsels: Conditional operators in Python

$
0
0

Python's conditional operators return Boolean values (True and False).

What are Booleans?

We have three lists here, two of which represent the same data.

>>> a=[1,2,3]>>> b=[1,2,3]>>> c=[4,5,6]

If we wanted to ask whether two objects represent the same thing in Python, we can use the equals-equals (==) operator (a.k.a. the "equality operator"):

>>> a==bTrue

The == operator will respond with either True or False.

>>> a==cFalse

True and False are both of the type bool, which stands for Boolean:

>>> type(True)<class 'bool'>

Booleans are how we represent "yes and no" or "affirmative and negative" in Python.

Booleans are often returned when using comparison operations, like equality (==).

Expressions that return either True or False (like a == b) are sometimes called Boolean expressions.

Where are Boolean expressions used?

Boolean expressions are often used …

Read the full article: https://www.pythonmorsels.com/conditional-operators/


Viewing all articles
Browse latest Browse all 24353

Trending Articles