INTERACTIVE ONLINE COURSE

Python 3

FOR BEGINNERS


"The first Python course that simply amazed me. Very well explained and easy to understand." (Alexandru Cosmin)

"The best Python course in Romania." (Iulian Geană)


ALL REVIEWS
LESSON 7
PAGE 3 / 5
Conditional Statements in Python
Home >>> Online Lessons, Python 3

Logical Operators

The logical operators are as follows: not (negation), and (and), or (or).

Except for the not operator, which is unary (operates on a single operand), the other logical operators are binary (operate on two operands). The operands can be of any type, such as boolean, integer, real, etc. The result will always be a boolean value – True or False.

EXAMPLES

Analyze the result of the following logical expressions by running the program:
Editor - lesson7_if.py
       
Console/Output done
DETAILS

The logical negation operator (not) works as follows: if the operand is a value different from 0 or True, the result is False; in any other case, the result is True.

The logical and operator (and). The way the result is obtained can be observed from the table below:

If both operands are different from False, the result is True; otherwise, it is False.

The logical or operator (or). The way the result is obtained can be observed from the table below:

The rule here is simple: if one of the operands is True, the result is True; otherwise, the result is False.

Therefore...

The decisions made are based on evaluating expressions that have a logical result - Yes or No. Let's continue.
Run the program and then proceed to the next page.
 home   list  CONTENTS   perm_identity   arrow_upward