I came across the code snippet in Mastering Object-oriented Python.
I don't understand the syntax of line 2. I understand that rank_str is a dictionary. What is the class_,
syntax and what is it doing?
The other part I don't understand is on line 8. If class_ is a class then why is suit
needed in the constructor when it is never referred to? Is it because the *Card classes have it as a parameter in their constructors?
1. def card( rank, suit ):
2. class_, rank_str= {
3. 1: (AceCard,'A'),
4. 11: (FaceCard,'J'),
5. 12: (FaceCard,'Q'),
6. 13: (FaceCard,'K'),
7. }.get(rank, (NumberCard, str(rank)))
8. return class_( rank_str, suit )
dict.get()
method?