0

Can someone help me with stalk class in python

Am lost

17th Jan 2023, 5:38 PM
Earnest M
Earnest M - avatar
11 odpowiedzi
+ 2
Which "stalk class"? In case you are referring to a particular task, please give a complete task description and link your code.
17th Jan 2023, 5:40 PM
Lisa
Lisa - avatar
+ 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.
17th Jan 2023, 7:18 PM
JuZip
+ 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 😉
18th Jan 2023, 7:38 AM
JuZip
+ 1
Hi Earnest M the code runs well. Where is the point you are lost?
17th Jan 2023, 7:02 PM
JuZip
17th Jan 2023, 6:00 PM
Earnest M
Earnest M - avatar
0
I don't have any knowledge about classes so I need a scope of it .....it runs but I don't understand it
17th Jan 2023, 7:03 PM
Earnest M
Earnest M - avatar
0
Classes will be covered in the Python Core course. Keep learning.
17th Jan 2023, 7:07 PM
Lisa
Lisa - avatar
0
Okay thanx
17th Jan 2023, 7:08 PM
Earnest M
Earnest M - avatar
0
Thanks alot
17th Jan 2023, 7:19 PM
Earnest M
Earnest M - avatar
0
It is easy, what do you need to class?
18th Jan 2023, 2:31 AM
Eliasib Cadena M
Eliasib Cadena M - avatar
0
python get element by id class name= "stalk".
18th Jan 2023, 2:55 PM
Andrei92