---
title: What is the difference between xrange and range in Python?
description: What is the difference between xrange and range in Python?
---

[Skip to content](https://help.datasciencedojo.com/migration/what-is-the-difference-between-xrange-and-range-in-python#main-content)

English

Show submenu for translations

[Customer portal](https://help.datasciencedojo.com/tickets-view?hsLang=en)

![DSD main logo.png\]](https://help.datasciencedojo.com/hs-fs/hubfs/DSD%20main%20logo.png?height=40&name=DSD%20main%20logo.png)

- [Default HubSpot Blog](https://help.datasciencedojo.com/blog)

Open main navigation

Close main navigation

- [Default HubSpot Blog](https://help.datasciencedojo.com/blog)
- English
  
  Show submenu for translations
- [Customer portal](https://help.datasciencedojo.com/tickets-view)
- Go to datasciencedojo.com

 Go to datasciencedojo.com

 How can we help?

- There are no suggestions because the search field is empty.

1. [Help Center](https://help.datasciencedojo.com/migration?hsLang=en)
2. [Python Programming](https://help.datasciencedojo.com/migration/python-programming?hsLang=en)

# What is the difference between xrange and range in Python?

In Python, the assignment statement (= operator) does not copy objects. Instead, it creates a binding between the existing object and the target variable name. To create copies of an object in Python, we need to use the copy module. Moreover, there are two ways of creating copies for the given object using the copy module -

 

Shallow Copy is a bit-wise copy of an object. The copied object created has an exact copy of the values in the original object. If either of the values is a reference to other objects, just the reference addresses for the same are copied.

Deep Copy copies all values recursively from source to target object, i.e. it even duplicates the objects referenced by the source object.

 

from copy import copy, deepcopy

list\_1 = \[1, 2, \[3, 5\], 4\]

\## shallow copy

list\_2 = copy(list\_1)

list\_2\[3\] = 7

list\_2\[2\].append(6)

list\_2 # output =\> \[1, 2, \[3, 5, 6\], 7\]

list\_1 # output =\> \[1, 2, \[3, 5, 6\], 4\]

\## deep copy

list\_3 = deepcopy(list\_1)

list\_3\[3\] = 8

list\_3\[2\].append(7)

list\_3 # output =\> \[1, 2, \[3, 5, 6, 7\], 8\]

list\_1 # output =\> \[1, 2, \[3, 5, 6\], 4\]

- [Data Science Bootcamp](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#main-content)

    - [Certificate](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#certificate)
    - [Logistics](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#logistics)
    - [Curriculum](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#curriculum)
    - [Target Audience](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#target-audience)
    - [Talk to an Advisor](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#talk-to-an-advisor)
    - [Prerequisites](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#prerequisites)
    - [Pricing](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#pricing)
    - [Policies](https://help.datasciencedojo.com/migration/data-science-bootcamp?hsLang=en#policies)
- [Large Language Models Bootcamp](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#main-content)

    - [Logistics](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#logistics)
    - [Curriculum](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#curriculum)
    - [Certificate](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#certificate)
    - [Prerequisites](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#prerequisites)
    - [Eligibility](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#eligibility)
    - [Talk to an advisor](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#talk-to-an-advisor)
    - [Pricing](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#pricing)
    - [Delivery](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#delivery)
    - [Program Overview](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#program-overview)
    - [Policies](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#policies)
    - [Registration](https://help.datasciencedojo.com/migration/large-language-models-bootcamp?hsLang=en#registration)
- [Agentic AI Bootcamp](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#main-content)

    - [Prerequisites](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#prerequisites)
    - [Logistics](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#logistics)
    - [Curriculum](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#curriculum)
    - [Program Overview](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#program-overview)
    - [Pricing](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#pricing)
    - [Preparatory Material](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#preparatory-material)
    - [Policies](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#policies)
    - [Talk to an Advisor](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#talk-to-an-advisor)
    - [Registration](https://help.datasciencedojo.com/migration/agentic-ai-bootcamp?hsLang=en#registration)
- [Registration](https://help.datasciencedojo.com/migration/registration?hsLang=en#main-content)

    - [Payment Methods](https://help.datasciencedojo.com/migration/registration?hsLang=en#payment-methods)
    - [Free Certificate](https://help.datasciencedojo.com/migration/registration?hsLang=en#free-certificate)
    - [Tuition Benefits](https://help.datasciencedojo.com/migration/registration?hsLang=en#tuition-benefits)
- [Pricing](https://help.datasciencedojo.com/migration/pricing?hsLang=en)
- [Community](https://help.datasciencedojo.com/migration/community?hsLang=en#main-content)

    - [FODAI 2025 - Sept Edition](https://help.datasciencedojo.com/migration/community?hsLang=en#fodai-2025-sept-edition)
    - [FODAI 2026](https://help.datasciencedojo.com/migration/community?hsLang=en#fodai-2026)
- [Python Programming](https://help.datasciencedojo.com/migration/python-programming?hsLang=en)
- [Platform Related Issues](https://help.datasciencedojo.com/migration/platform-related-issues?hsLang=en#main-content)

    - [Community](https://help.datasciencedojo.com/migration/platform-related-issues?hsLang=en#community)
- [Bootcamps](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#main-content)

    - [Formats and Delivery](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#formats-and-delivery)
    - [Certificates](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#certificates)
    - [Policies](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#policies)
    - [Session Access](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#session-access)
    - [Benefits](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#benefits)
    - [Exercises](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#exercises)
    - [Tuition Benefits](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#tuition-benefits)
    - [Logistics](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#logistics)
    - [Testimonials](https://help.datasciencedojo.com/migration/bootcamps?hsLang=en#testimonials)
- [Homework and Notebooks](https://help.datasciencedojo.com/migration/homework-and-notebooks?hsLang=en#main-content)

    - [Personal Assigments](https://help.datasciencedojo.com/migration/homework-and-notebooks?hsLang=en#personal-assigments)
- [Free Courses](https://help.datasciencedojo.com/migration/free-courses?hsLang=en)
- [Data Science for Business](https://help.datasciencedojo.com/migration/data-science-for-business?hsLang=en#main-content)

    - [Program Overview](https://help.datasciencedojo.com/migration/data-science-for-business?hsLang=en#program-overview)
- [Practicum](https://help.datasciencedojo.com/migration/practicum?hsLang=en#main-content)

    - [Logistics](https://help.datasciencedojo.com/migration/practicum?hsLang=en#logistics)
    - [Program Overview](https://help.datasciencedojo.com/migration/practicum?hsLang=en#program-overview)
- [Blog](https://help.datasciencedojo.com/migration/blog?hsLang=en#main-content)

    - [Content Collaboration](https://help.datasciencedojo.com/migration/blog?hsLang=en#content-collaboration)
    - [Guest Posts](https://help.datasciencedojo.com/migration/blog?hsLang=en#guest-posts)
    - [Link Exchanges/Insertions](https://help.datasciencedojo.com/migration/blog?hsLang=en#link-exchanges-insertions)
- [Employment Assistance](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#main-content)

    - [Resumes](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#resumes)
    - [Internships](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#internships)
    - [Profile Shortlisting](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#profile-shortlisting)
    - [Career Paths](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#career-paths)
    - [Applying for Mentor](https://help.datasciencedojo.com/migration/employment-assistance?hsLang=en#applying-for-mentor)
- [Machine Learning](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#main-content)

    - [Unsupervised](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#unsupervised)
    - [Supervised](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#supervised)
    - [Statistics](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#statistics)
    - [Deep Learning](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#deep-learning)
    - [Timeseries](https://help.datasciencedojo.com/migration/machine-learning?hsLang=en#timeseries)
- [Data Analysis](https://help.datasciencedojo.com/migration/data-analysis?hsLang=en)
- [R Language](https://help.datasciencedojo.com/migration/r-language?hsLang=en)
- [Python for Data Science](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#main-content)

    - [Prerequisites](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#prerequisites)
    - [Pricing](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#pricing)
    - [Curriculum](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#curriculum)
    - [Program Overview](https://help.datasciencedojo.com/migration/python-for-data-science?hsLang=en#program-overview)
- [SQL](https://help.datasciencedojo.com/migration/sql?hsLang=en)
- [Introduction to Power BI](https://help.datasciencedojo.com/migration/introduction-to-power-bi?hsLang=en)
- [Power BI](https://help.datasciencedojo.com/migration/power-bi?hsLang=en)
- [Programming and Tools](https://help.datasciencedojo.com/migration/programming-and-tools?hsLang=en#main-content)

    - [SQL](https://help.datasciencedojo.com/migration/programming-and-tools?hsLang=en#sql)
- [Partnerships](https://help.datasciencedojo.com/migration/partnerships?hsLang=en)

- [Default HubSpot Blog](https://help.datasciencedojo.com/blog)

[![Chill listening crop-3](https://help.datasciencedojo.com/hs-fs/hubfs/DSD%20main%20logo.png?width=95&height=24&name=DSD%20main%20logo.png "Chill listening crop-3")](https://datasciencedojo.com)

<https://www.linkedin.com/company/data-science-dojo/> <https://twitter.com/DataScienceDojo> <https://www.youtube.com/c/Datasciencedojo> <https://instagram.com/data_science_dojo?igshid=YmMyMTA2M2Y=> <https://www.facebook.com/datasciencedojo>

Copyright © 2026, Data Science Dojo