There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
I am working on step one of this exercise and can’t seem to get it right but I don’t want to look at the solution because the last time I did that on another exercise it wouldn’t let me try the exercise again and I learned nothing.
This is my dunder init, but it keeps asking if I put “limit” as a parameter. If I take out the “=1000” it recognizes the parameter, but then asks if I set the default to 1000. I tried changing it in properties to 1000 but it says I need to set the default in the () of init. I have tried every variation I can think of and just can’t get it to work. Thanks for any help!
I actually had not gotten it yet, so thank you so much! Yeah, it doesn’t seem to make much sense not putting size in brackets, but such is life. Thanks again!
We set the instance variable size to 0 when we initialize the Stack because it starts out with no items in it. Since size always starts out at 0, we do not represent it as a parameter, as it does not need to be set via an argument when the Stack is instantiated.
We should keep in mind that the __init__ method is free to create instance variables in addition to ones that are represented by its parameters. It can also perform other tasks related to setting up an instance of the class to which it belongs.
Can somebody explain to me what this phrase actually means:
“Inside the method, set the instance limit property to the passed in value of limit .”
I can’t make sense of this.
Also just to say that I made the same mistake of putting size in the brackets. I understand the explanation, but it is hard to get my head around it. I suppose understanding oftern comes with practice.
That instruction is asking us to assign the value of the limit parameter to an instance variable of the same name within the __init__ method of Stack with this statement:
self.limit = limit
In a later exercise, we will use that instance variable to constrain the size of the Stack, as follows:
Thanks for that. Should it not say “Inside the method, set the instance limit property to that passed in the value of limit .” That would make more sense to me. Or is it just me?
Your rephrasing of the instruction is accurate, and seems pretty good. Codecademy staff do read the discussion forums, and one of them might consider whether to revise that instruction for clarity.
I don’t understand how we can calculate the size of the stack when there is no code was written to count number of nodes. we just set in the beginning the self.size = 0. How the code is supposed to count the number of nodes. And then we subtract -1 from the base which equals 0. Don’t get it?
The size variable is created for keeping track of how many items are in the Stack instance. It always should start at 0 at the time that we create the instance, so the __init__ method is the appropriate place for initializing it.
In the __init__ method, we can perform whatever tasks are necessary for properly setting up an instance of a class.