0
Can someone help me with stalk class in python
Am lost
12 Answers
+ 2
Which "stalk class"?
In case you are referring to a particular task, please give a complete task description and link your code.
+ 2
Look here: https://docs.python.org/3/tutorial/classes.html
"Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state."
A class is a blueprint which you can see as a container for attributes and functions applying to objects of that class.
So all in the class block is part of your class, here 4 functions + the __init__ function which is called when you create an object.
That's done by s = Stack() here. So s will be an object of stack class.
Then you use three times the function of the class. So you take the object s an with s.push() you apply what you coded in the function push. The same with the other.
Try to run the is_empty function on your object. As it's not used yet, you can get a feeling for how to do it.
+ 2
Earnest M as your example doesn't have attributes (see them like variables of the class) you could add one to the class. maybe for storing the size of the stack (just to know how it works)
Then you add to the class-functions a statement to increase the size in push and decrease it in pop by 1.
Try it and come back with it running or questions 😉
+ 1
Hi Earnest M the code runs well. Where is the point you are lost?
0
I don't have any knowledge about classes so I need a scope of it .....it runs but I don't understand it
0
Classes will be covered in the Python Core course. Keep learning.
0
Okay thanx
0
Thanks alot
0
It is easy, what do you need to class?
0
python get element by id class name= "stalk".