We've already learned that the particle は is used to mark the topic of a sentence. Apart from this usage, は is also used as a contrast marker.
You can use the particle は as a contrast marker by using it multiple times.
|I don't like horses, but I like dogs.||馬 は 好き じゃ ない が、 犬 は 好き よ。uma wa suki ja nai ga, inu wa suki yo.|
Note that in the sentence above, 馬 and 犬 are subjects of the clauses they're in. But to emphasize the contrast, は is used instead of the subject marker が. We cannot use the particle は after the particle が. The contrast marker は can also not be combined with the object marker を, and therefore also replaces it if we want to contrast two objects.
|(I) did not buy a game. (I) bought a notebook.||ゲーム は 買わなかった。 ノート は 買った。gemu wa kawanakatta. nooto wa katta.|
Note that は's role as contrast marker is consistent with its role as topic marker, as there are multiple topics that are talked about: as for A it is X, as for B it is Y.
This becomes even more apparent in the following sentences, which show that the contrast marker does not need to be used multiple times in a sentence, and that making something the topic is already inherently contrasting it with other things that are not the topic.