June 2019
Beginner to intermediate
770 pages
19h 24m
English
We'll use the BlackJackCard class as an example to see what happens when we attempt comparisons where the two operands are from different classes.
The following is a Card instance that we can compare against the int values:
>>> two = card21(2, "♠")>>> two < 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: Number21Card() < int() >>> two > 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unorderable types: Number21Card() > int()
This is what we expected: the subclass of BlackJackCard, Number21Card, doesn't provide the required special methods to implement a comparison against integers, so there's ...
Read now
Unlock full access