Does toString
have a function besides checking work?
Yes, having a toString
method is useful for anytime the main program wants to have a string version of an object --- maybe to print and debug, or to give a status update, or to add to a list of strings to do other manipulations with, ...
Why does self
act differently from other variables?
self
is a reserved keyword that Python uses within an object to refer to that object's own information (variables and methods).
I am wondering if you can define an object within an object.
You can certainly use objects inside other objects! We've seen this already, for example in the graphics unit, every Circle object has a center Point (which is an object) which it stores as its own information.
If you're asking about WRITING a class, then: no, your class definitions need to be separate (not nested), even if they will be used together.
How do I do things with this deck of cards?
We'll see next time how to shuffle, deal, and play some games with the deck of cards.
How do you include every possible function in these classes?
Including every function probably isn't possible! But a top-down design can help us sketch out what functions we want/need the class to have, depending on the way the main program is structured.
I keep getting None
on my deck.toString()
. I'm stumped.
This is a very common mistake --- if your function or method does not include a return
statement, then by default, Python returns the special value None
. This comes up if you have assigned your function return value to be stored in a variable, or printed... if the function returns None
, then that's what you'll see displayed!