GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • C programming
  • C++ programming
  • Java programming
  • Python programming
  • HTML
  • CSS
  • Codenora IDE (opens in a new tab)
  • About us
  • Pricing
  • Contact us
  • Privacy policy
  • Terms of service
  • Refund and Cancellation

This view

  • Original page
  • New address

GeezerVison is showing www.dremendo.com — Identity Operators in Python | Dremendo

  • Dremendo
  • C
  • C++
  • Java
  • Python
  • HTML
  • CSS
  • More
    • Home
    • C Tutorial
    • C++ Tutorial
    • Java Tutorial
    • Python Tutorial
    • HTML Tutorial
    • CSS Tutorial
?>
profile image
Announcements
No new announcements.
mentora icon
Python Programming Tutorial
  • Python Basic Concepts
    • Introduction
    • Variable
    • Data Types
    • Naming Conventions
    • Typecasting
  • Operators in Python
    • Operators
    • Assignment Operators
    • Arithmetic Operators
    • Relational Operators
    • Logical Operators
    • Identity Operators
    • Membership Operators
    • Operator Precedence
  • Input and Output in Python
    • Environment Setup
    • print() Function
    • input() Function
    • Comments
  • Decision Making in Python
    • Decision Making
    • if Statement
    • if else Statement
    • if elif Statement
  • Mathematical Functions
    • Mathematical Functions
  • Loops in Python
    • Loops
    • for Loop
    • while Loop
  • String in Python
    • String
    • String Methods
  • Built-in Data Structures in Python
    • Lists
    • Tuples
    • Sets
    • Dictionaries
  • Arrays in Python
    • Arrays
  • Searching in Python
    • Linear Search
    • Binary Search
  • Sorting in Python
    • Bubble Sort
    • Selection Sort
    • Insertion Sort
  • Function in Python
    • Function
    • Recursive Function
    • Lambda Function
    • Closures
    • Decorators
    • Generators
  • OOPs in Python
    • Classes and Objects
    • Instance Variables
    • Instance Methods
    • Class Variables
    • Static Methods
    • Inheritance
    • Types of Inheritance
    • MRO
    • Polymorphism
    • Abstract Classes
  • User-Defined Data Structures in Python
    • Stack
    • Queue
    • Circular Queue
    • Double Ended Queue
    • Singly Linked List
    • Doubly Linked List
    • Stack using Linked List
    • Queue using Linked List
  • Modules in Python
    • Modules
    • Time Module
    • Datetime Module
    • OS Module
    • Shutil Module
    • Sys Module
    • JSON Module
    • Random Module
  • Regular Expression in Python
    • Regular Expression
  • Exceptions in Python
    • Exception Handling
  • File Handling in Python
    • Text File Handling
    • Binary File Handling
    • CSV File Handling

bookmark
Table of Contents

    Identity Operators in Python

    In this lesson, we will learn what is the Identity Operators and how it works in Python programming with some examples.

    What is Identity Operators

    Identity operators in Python are used to check if two variables point to the same object in memory. Even if two variables have the same value, it does not mean they are the same object.

    Video Explanation

    Click the button below to watch the explanation.

    Please wait while the video is loading....
    video image

    There are 2 types of identity operators in Python and they are:

    • is
    • is not

    Now let's see the examples of the identity operators one by one for more understanding.

    is Operator

    The is operator checks if two variables refer to the same object in memory. If they are identical, the result is True; otherwise, it is False.

    Example
    a = 15         # integer value
    b = 15         # integer value
    c = "apple"    # string value
    d = "apple"    # string value
    e = [1, 2, 3]    # list
    f = [1, 2, 3]    # list
    x = a is b     # output of x is True
    y = c is d     # output of y is True
    z = e is f     # output of z is False

    In the example above, the output of x is True because both variables a and b are of integer type and have the same value. Similarly, the output of y is True because both variables c and d are strings with the same value. However, the output of z is False because both variables e and f are lists stored in different memory locations.

    In the case of lists, even if their values are the same, they are not identical because they are stored in different memory locations.

    is not Operator

    The is not operator checks if two variables are not identical (do not refer to the same object). If they are not identical, the result is True; otherwise, it is False.

    Example
    a = 15         # integer value
    b = 15         # integer value
    c = "apple"    # string value
    d = "ball"     # string value
    e = [1, 2, 3]    # list
    f = [1, 2, 3]    # list
    x = a is not b     # output of x is False
    y = c is not d     # output of y is True
    z = e is not f     # output of z is True

    In the example above, the output of x is False because both variables a and b are of integer type and have the same value. However, the output of y is True because both variables c and d are strings, but their values are not the same. Similarly, the output of z is True because both variables e and f are lists stored in different memory locations.

    Test Your Knowledge

    Attempt the questions in the exercise to check whether you have understood the lesson clearly.

    Exercise
    Test Your Knowledge
    Previous Next

    We care about your privacy

    Dremendo uses cookies and similar technologies that are necessary for the site to work properly, understand how you interact with our website, and measure the effectiveness of our marketing. By clicking Accept All, you consent to the use of non-essential cookies and similar technologies for analytics, advertising, and ad measurement, as described in our Privacy Policy.

    Cookie Preferences

    Choose which types of cookies Dremendo may use.

    Necessary Cookies

    Required for essential website functionality and security.

    Allow
    Analytics Cookies

    Help us understand how visitors use Dremendo.

    Allow
    Marketing Cookies

    Help us measure advertising performance and understand interactions with our advertisements.

    Allow
    Mentora Question Asked: 0 / 20

    Hi, I’m Mentora!

    I’m your personal AI tutor from Dremendo. Ask me anything, and I’ll help you understand it in a simple and easy way.

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.