reset password
Author Message
rabbott
Posts: 1649
Posted 20:00 Jan 27, 2019 |

How carefully did you read Hjelle? Did you ask yourself some of all of the following questions?

 

  • Hjelle says, "As an example, you can call len() on any Python object that defines a .__len__() method." Is that true for all functions? For example, if you define a .__abc__() method does that create an abc() function?

 

  • What does PEP stand for?

 

  • When do you recommend using type comments and when type hints?

 

  • How do you write card suits: "♠ ♡ ♢ ♣"?

 

  • What is random.shuffle?

 

  • Do you understand how deal_hands() works?

 

  • What does names = "P1 P2 P3 P4".split() do?

 

  • What does for name, cards in hands.items() do?

 

  • What does card_str = " ".join(f"{s}{r}" for (s, r) in cards) do?

 

  • In the line  version: Tuple[int, int, int] = (3, 7, 1) the type of version is Tuple[int, int, int]. Does that mean that the type of version is a list of three ints?

 

  • In 
from typing import List, Tuple
Card = Tuple[str, str]

Card is a type alias. Is it also an object the program can manipulate? For example, can you write and execute: print(Card)?

 

  • In the method player_order, what does the return line return?

 

  • What does it mean to say that "int is a subtype of float but not a subclass of float."?

 

  • When I ran
reveal_type(choose(["Guido", "Jukka", "Ivan"]))
reveal_type(choose([1, 2, 3]))
reveal_type(choose([True, 42, 3.14]))
reveal_type(choose(["Python", 3, 7]))

I got Choosable? as the revealed type in all cases, which is not what Hjelle got. What did you get?

 

  • Which parts of this tutorial should you expect to understand, to remember? What should you do about the other parts? How do you deal with situations in which there is more information than you can handle?
Last edited by rabbott at 21:17 Jan 27, 2019.