a question about lists

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

  1. pythonbeginner

    pythonbeginner

    Joined:
    Sep 1, 2012
    Messages:
    1
    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. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JustSomeGuy

    Sorting lists of lists...

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

    lists of lists

    Jon Slaughter, Dec 13, 2004, in forum: C++
    Replies:
    4
    Views:
    408
    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:
    392
    Charlotte Henkle
    Sep 26, 2004
  4. robin
    Replies:
    10
    Views:
    533
    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:
    391
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
Loading...

Share This Page