Mutable Objects

  • Comments posted to this topic are about the item Mutable Objects

  • the available answers to the question are incorrect as you are printing J who's value is 1, the answers available are relevant if you print(i) not print(j)

  • IRL11 - Wednesday, April 25, 2018 3:20 AM

    the available answers to the question are incorrect as you are printing J who's value is 1, the answers available are relevant if you print(i) not print(j)

    +1

  • An interesting question and good explanation with useful links, thanks Steve. My first tip was that the value
    of the name j would not change, but fortunately in the title of today's QotD is a little help ...😉

  • IRL11 - Wednesday, April 25, 2018 3:20 AM

    the available answers to the question are incorrect as you are printing J who's value is 1, the answers available are relevant if you print(i) not print(j)

    Are you looking at the code in the email or in the QOTD page at SSC (after clicking the "Click Here to find out if you are right")

    The email has

    >>> i = [1,2,3]
    >>> j = 1


    but the QOTD page has
    >>> i = [1,2,3]
    >>> j = i


  • IRL11 - Wednesday, April 25, 2018 3:20 AM

    the available answers to the question are incorrect as you are printing J who's value is 1, the answers available are relevant if you print(i) not print(j)

    Where did you see this? The code is
    i = [2,3,4]
    j= i
    i [1] = 4
    print(j)

    This would show that j is altered as well.

  • As Timwell pointed out the examples in the email and the QoTD are different, I must have looked at the example in the email and went looking for the available answer based on that.

  • Nice one, thanks Steve
    From reading the thread, i'm glad i don't wait for the e-mail before answering

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

  • Hi,

    Sorry, I believe the correct answer is J=1,2,3, J gets the value of I and after J is printed.

  • Don't look in the newsletter. There was a typo.

    j is assigned i. This means they both point to the same address in memory. When i is changed, j also is changed because it's not a copy, but a pointer.

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply