Identity Operators

Python · Operators

Theory

is and is not check whether two names refer to the very same object in memory, by comparing identities (what id() returns). == instead asks whether two objects have equal values. With a = [1, 2, 3], b = a and c = [1, 2, 3]: a is b is True because both names point to one list, while a is c is False because c is a separate list that merely holds the same values, even though a == c is True.

The main correct use of is is checking for singletons, objects Python guarantees exist only once: None, True and False. Write if value is None, not == None. Avoid is for numbers and strings: CPython reuses some small integers and short strings for efficiency, so 5 is 5 may happen to be True while larger values behave differently. That is an implementation detail, not a language rule, so results can change between Python versions and contexts.

Why we use it

Sometimes you need to know whether two variables are aliases of one object, for example to understand why changing one list changed 'another'. is answers that question, and is None is the clear, reliable way to test for a missing value.

When to use it

Use is / is not only for None, True, False or when you deliberately check aliasing. Use == for comparing values of numbers, strings, lists and everything else.

How it works

  1. Evaluate a is c
  2. Get the identity (memory object) of a
  3. Get the identity of c
  4. Are they the exact same object? Yes: Return True. No: Return False, even if the values are equal.
  5. print(a is b, a is c) shows True False

Syntax

a is b
a is not b

Example

a = [1,2,3]
b = a
c = [1,2,3]
print(a is b, a is c)

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic