Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
In the last section, we finished up the constructor on the deck class.
Now I'm going to assume that everything worked correctly, but in reality, I don't really know.
It would be really great if there is some way that we could kind of inspect this card's property right
here on the deck that we created inside of our main function.
For example, maybe if we could print out that entire list of cards to the terminal or the console over
here, we could then verify that the correct number and type of card is being added to the cards list
right here.
So let's try that out.
Let's try using that print function that we looked at previously to print out the deck that gets created
right here.
And maybe we'll be able to figure out what cards actually got inserted into this card list.
So to use that print function, I'm going to assign the deck we created right here to a deck variable.
I then called a print function and I'll pass the deck in like so.
Then I'll click run on the top, right, and we'll see what happens.
OK, so kind of underwhelming.
I got an output right here of instance of DEC.
So what really happens when we pass a variable to the print function?
It's kind of hoping we would see all the information that is contained within the stack, but instead
we got this very default, little bit of information.
So let's take a look at a diagram that's going to help us understand what the print function is really
doing for us.
OK, so here's what's happening, you and I are calling the print function and then we're passing in
on here, I put value technically we are passing in a variable or a reference, but I think you get
the idea here.
So what the print function does is it looks at that value and it says, hey, do you have a two string
method?
If that value has a two string method defined on it, it will be executed and then the result of that
method will be printed out to the console.
So if we want to customize how any value gets printed out, we can define that two string method and
we can customize what it returns to change what actually gets printed out.
Now, the two string function right here that I've listed out, this is a very special function name.
So when the print function is used and we Parzania value, the print function is going to look specifically
for a function called exactly to string.
So if we want to customize the print function, we have to define to string on our class.
So let's try this out and see what happens.
So I'm going to go back over to my code.
Here's my deck class.
So I want to customize how this thing prints itself out.
And I can do so by defining the two string method on it.
So I'm going to go down below my constructor, but still inside of the class body and I'll define the
two string function on here.
Now, just to make sure that this works the way we expect, I'm going to first try returning a very
silly string, I'll say something like this is a deck like so.
So now that we've defined this two string function print up here is going to call to string, any time
we pass in an instance of a deck, we're going to return the string right here.
And the print function is going to use the string as the representation of our deck.
So let's now try running this code again and seeing what happens.
OK, so now we see this is a deck as opposed to the previous instance of deck that we had before.
OK, so that definitely works to customize our print statement, but we're still not really able to
view the data that exists inside of our list of cards right here.
So let's take a quick pause.
We'll come back in the next section and we're going to continue working on this two string function.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.