Please explain what is happening inside the solution

Would you please help me understand line by line what is happening in the following solution code:

class NewList(DQ):                      # Creates a new object NewList
    def __init__(self, initial_state):  # Adds arguments self and initial_state = initial_state       # Assigns initial_state to an attribute called data
my_list = NewList([1, 2, 3, 4, 5])      # Assigns the list [1, 2, 3, 4, 5] to variable my_list
print(                     # Calls the list [1, 2, 3, 4, 5] using the the variable name

I am really just confused over line 3 of the code. Would it be correct that this is essentially saving the list [1, 2, 3, 4, 5] as the initial state of the NewList class?

Thank you

That particular Mission covers Python Classes in sufficient detail till that point to be able to understand what is happening in that code.

Do you have any specific questions regarding the code that the first 7 or 8 Steps in that Mission weren’t able to explain in appropriate detail?

Thank you Doctor, I had not finished typing my question. Would you please refer to it again.

1 Like

Yes, that would be correct.

The list is passed as an input when the NewList Class is instantiated as my_list. That list is then stored in the attribute data.

So, that list is basically stored in data now. And anytime you wish to access it you can access it using, since my_list is an instance of the Class NewList, and data is an attribute of that Class.

Hopefully that helps?

Absolutely, thank you

1 Like

Any idea why it doesn’t works? did I do anything wrong, or is it some glitch ?

Since this is not related to the original question, please create a new post for it.