a question about lists

Discussion in 'Python' started by pythonbeginner, Sep 1, 2012.

  1. pythonbeginner

    pythonbeginner

    Joined:
    Sep 1, 2012
    Messages:
    1
    Likes Received:
    0
    I am new to Python. Here is a question I have about lists:
    It is said that lists are mutable and tuples are immutable. But when I write the following:

    L1 = [1, 2, 3]
    L2 = (L1, L1)
    L1[1] = 5
    print L2

    the result is
    ([1, 5, 3], [1, 5, 3])

    instead of
    ([1, 2, 3], [1, 2, 3])

    But L2 is a tuple and tuples are immutable. Why is it that when I change the value of L1, the value of L2 is also changed?
     
    pythonbeginner, Sep 1, 2012
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. JustSomeGuy

    Sorting lists of lists...

    JustSomeGuy, Jun 17, 2004, in forum: C++
    Replies:
    0
    Views:
    546
    JustSomeGuy
    Jun 17, 2004
  2. Jon Slaughter

    lists of lists

    Jon Slaughter, Dec 13, 2004, in forum: C++
    Replies:
    4
    Views:
    730
    Buster
    Dec 13, 2004
  3. Charlotte Henkle

    Counter for items in lists in lists?

    Charlotte Henkle, Sep 25, 2004, in forum: Python
    Replies:
    8
    Views:
    683
    Charlotte Henkle
    Sep 26, 2004
  4. robin
    Replies:
    10
    Views:
    727
    Dave Hansen
    Apr 12, 2006
  5. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    831
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  6. yomgui

    list of lists of lists ....

    yomgui, Jul 28, 2006, in forum: Python
    Replies:
    6
    Views:
    660
    yomgui
    Jul 31, 2006
  7. Daniel Nogradi
    Replies:
    3
    Views:
    587
    Dennis Lee Bieber
    Nov 10, 2006
  8. ardief
    Replies:
    14
    Views:
    960
    Paddy
    Feb 3, 2007
Loading...