How do I setup a class that represents an interface? Is this just an abstract base class? 17 s 17 To expand on the answer by bradtgmurray, you may...
  • April 19, 2022
  • 0 Comments
What are the differences between these two code snippets? Using type(): import types if type(a) is types.DictType: do_something() if type(b) in types.StringTypes: do_something_else() Using isinstance(): if isinstance(a, dict): do_something()...
  • April 13, 2022
  • 0 Comments
Why does the following class declaration inherit from object? class MyClass(object): ... 6 Is there any reason for a class declaration to inherit from object? In Python 3, apart...
  • April 12, 2022
  • 0 Comments
When planning out my programs, I often start with a chain of thought like so: A football team is just a list of football players. Therefore, I should represent...
  • April 11, 2022
  • 0 Comments
If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I...
  • April 11, 2022
  • 0 Comments
Why prefer composition over inheritance? What trade-offs are there for each approach? When should you choose inheritance over composition? 3 33
  • April 10, 2022
  • 0 Comments
They are absolutely different. Inheritance is an “is-a” relationship. Composition is a “has-a”. You do composition by having an instance of another class C as a field of your...
  • April 8, 2022
  • 0 Comments