Getting Started

Python - IntroductionPython - Hello World ProgramPython - SyntaxPython - Data TypesPython - Variables

Operators

Python - Arithmetic OperatorsPython - Relational OperatorsPython - Logical OperatorsPython - Assignment OperatorsPython - Bitwise OperatorsPython - Membership OperatorsPython - Identity OperatorsPython - Increment and Decrement Operators

Conditions

Python - If Else statement

Loop

Python - While LoopPython - For Loop

Numbers

Python - NumbersPython - Number Conversion

Strings

Python - StringsPython - String OperatorsPython - String FormattingPython - String MethodsPython - String Format Method

List

Python - ListPython - List Methods

Tuple

Python - Tuple

Set

Python - SetPython - Set Methods

Dictionary

Python - DictionaryPython - Dictionary Methods

Functions

Python - FunctionsPython - Functions - Variable length argumentsPython - Lambda Function

Scope of Variables

Python - Scope of Variables

Modules

Python - ModulesPython - Math ModulePython - JSON ModulePython - datetime ModulePython - time Module

I/O

Python - Read input from keyboard

File

Python - File Handling

Exception Handling

Python - Exception Handling

OOP

Python - Classes and ObjectsPython - Class Constructor __init__ methodPython - Class Destructor __del__ methodPython - Built-in Class AttributesPython - InheritancePython - Method OverridingPython - Method Overloading

Package Management

Python - PIP

Python - MySQL

Python - MySQL - Getting StartedPython - MySQL - Insert dataPython - MySQL - Select dataPython - MySQL - Update dataPython - MySQL - Delete data

Python - CSV

Python - Read data from CSV filePython - Write data in CSV file

Python - Logical Operators

Python

python logo

In this tutorial we will learn about Logical operators in Python.

Following are the list of Logical operators in Python

Click here if you want to read more about Boolean Algebra.

Logical and

The logical and operator will give True value if both the operands are True. Otherwise, it will give False.

Truth table of logical and operator.

ABA and B
FalseFalseFalse
FalseTrueFalse
TrueFalseFalse
TrueTrueTrue

In the following Python program we will get True only if both expressions evaluates to True.

# variables
a = 10
b = 20
x = 40
y = 50

m = a < b    # this will give True
n = y > x    # this will give True

print("Result: ", (m and n))

Output of the above code.

Result: True

Logical or

The logical or operator will give True value if any one of the operand is True. If both are False then it will return False.

Truth table of logical or operator.

ABA or B
FalseFalseFalse
FalseTrueTrue
TrueFalseTrue
TrueTrueTrue

In the following Python program we will get True if any one of the expression evaluates to True.

# variables
a = 10
b = 20
x = 40
y = 50

m = a <= b    # this will give True
n = y < x     # this will give False

print("Result: ", (m or n))

Output of the above code.

Result: True

Logical not

The logical not operator will give True value if the operand is False. And it will return False value if the operand is True.

Truth table of logical not operator.

Anot A
FalseTrue
TrueFalse

In the following example we will get True only if the expression evaluates to False.

# variables
a = 10
b = 20

m = a > b    # this will give False

print("Result: ", (not m))

Output of the above code.

Result: True

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT