Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8182161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:46:02+00:00 2026-06-07T00:46:02+00:00

a=[1,2,3] b=[4,5,6] c=[] d=[] Whats the difference between these two statements? c[:]=a d=b[:] But

  • 0
a=[1,2,3]
b=[4,5,6]
c=[]
d=[]

Whats the difference between these two statements?

c[:]=a
d=b[:]

But both gives the same result.

c is [1,2,3] and d is [4,5,6]

And is there any difference functionality wise?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:46:03+00:00Added an answer on June 7, 2026 at 12:46 am

    c[:] = a it means replace all the elements of c by elements of a

    >>> l = [1,2,3,4,5]
    >>> l[::2] = [0, 0, 0] #you can also replace only particular elements using this 
    >>> l
    [0, 2, 0, 4, 0]
    
    >>> k = [1,2,3,4,5]
    >>> g = ['a','b','c','d']
    >>> g[:2] = k[:2] # only replace first 2 elements
    >>> g
    [1, 2, 'c', 'd']
    
    >>> a = [[1,2,3],[4,5,6],[7,8,9]]
    >>> c[:] = a      #creates a shallow copy
    >>> a[0].append('foo') #changing a mutable object inside a changes it in c too
    >>> a
    [[1, 2, 3, 'foo'], [4, 5, 6], [7, 8, 9]]
    >>> c
    [[1, 2, 3, 'foo'], [4, 5, 6], [7, 8, 9]]
    

    d = b[:] means create a shallow copy of b and assign it to d , it is similar to d = list(b)

    >>> l = [1,2,3,4,5]
    >>> m = [1,2,3]
    >>> l = m[::-1] 
    >>> l
    [3,2,1]
    
    >>> l = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    >>> m = l[:] #creates a shallow copy 
    >>> l[0].pop(1) # a mutable object inside l is changed, it affects both l and m
    2
    >>> l
    [[1, 3], [4, 5, 6], [7, 8, 9]]
    >>> m
    [[1, 3], [4, 5, 6], [7, 8, 9]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Objective C (if that matters) is there a difference between these two statements?
What is difference between these two statements: var result = from c in context.CustomerEntities
What's the difference between these two jQuery statements? They seem to do the same
What is the difference between these two statements? String str = stackoverflow; & String
What's the difference between these two statements? I use them in my rails app
I have a class named A . What the difference between these two statements?
What is the difference between these two Html statements. <asp:Image runat=server ID=imgHelp ImageUrl=~/images/help.gif />
what is the difference between these two statements? which is better with respect to
In Access, what is the difference between these two statements? DBEngine.BeginTrans and DBEngine.Workspaces(0).BeginTrans The
What is the difference between these two declarations of a list of lists? >>>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.