CIT PYTHON COHORT THREE
  • CIT Python Cloud Software Engineering
  • week one
    • What is Python
    • Python Syntax
    • variables
    • Numbers / Integers
  • week Two
    • Control Flow Statements
      • If Statements
      • For Loops
      • While Loops
      • Break and Continue Statements
    • Operators
      • Assignment Operators
      • Arithmetic Operators
      • Comparison Operators
      • Logical Operators
      • Relational Operators
      • Bitwise Operators
      • Identity Operators
      • Membership Operators
    • Data Types
      • Strings
      • Numbers
      • Booleans
      • Lists
      • Dictionaries
      • Tuples
      • Sets
  • Week 3
    • Functions
      • Function Arguments
      • Python Recursion
      • Python Anonymous/Lambda Function
    • Object Oriented Programming
      • Classes
      • Inheritance
      • Polymorphism
      • Abstraction
      • Encapsulation
    • Python Modules
      • Python Packages
      • Python Built-in Modules
      • Python Standard Library
      • Python Third Party Modules
    • Python Exceptions
      • Python Try Except
      • Python Raise
      • Python Assert
      • Python User-defined Exceptions
  • Week 4
    • Python File Handling
  • Week6
    • Data Structures and Algorithms
      • DSA Introduction
      • What is an Algorithm?
      • Data Structures and Types
      • Stack
      • Queue
      • Linked List
      • Bubble Sort Algorithm
      • Selection Sort Algorithm
      • Insertion Sort Algorithm
      • Merge Sort Algorithm
      • Quick Sort Algorithm
  • Week8
    • Cryptography
      • Reverse Cipher
      • Caesar Cipher
      • Hash Functions
        • Applications of Hash Functions
        • Examples of Hash Functions
  • Assignments and Solutions
    • Loops
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. week Two
  2. Operators

Logical Operators

In Python, Logical operators are used on conditional statements (either True or False). They perform Logical AND, Logical OR and Logical NOT operations.

Operator
Meaning
Example

and

Logical AND - True if both operands are true

5 > 3 and 3 > 2 = True

or

Logical OR - True if either operand is true

5 > 3 or 3 > 2 = True

not

Logical NOT - True if operand is false

not 5 > 3 = False

Example 1: Logical operators in Python

x = True
y = False

print('x and y is',x and y)

print('x or y is',x or y)

print('not x is',not x)

Output:

x and y is False
x or y is True
not x is False

and will result into True only if both the operands are True

The truth table for and is given below:

Truth table for and

A
B
A and B

True

True

True

True

False

False

False

True

False

False

False

False

or will result into True if any of the operands is True.

The truth table for or is given below:

Truth table for or

A
B
A or B

True

True

True

True

False

True

False

True

True

False

False

False

not operator is used to invert the truth value.

The truth table for not is given below:

Truth table for not

A
not A

True

False

False

True

some example of their usage are given below

>>> True and False
False
>>> True or False
True
>>> not False
True
PreviousComparison OperatorsNextRelational Operators

Last updated 2 years ago

Was this helpful?