OOPL: JPL Python

  • Spring 2022
  • 26 Apr - 24 May 2022


Schedule

Week #1
Tue, 26 Apr 2022
Examples: Exercise #1: Notes: References:
Takeaways:
  • assertions are not good for testing
  • unittest is good for testing
  • assertions are not good for user errors
  • exceptions are good for user errors
Thu, 28 Apr 2022
Examples: Exercise #2: Notes: References:
Takeaways:
  • user-defined exception classes should have Exception as their parent
  • in a try-except block the else clause only runs if no exception is raised
  • in a try-except block the finally clause always runs
  • == compares value
  • is compares identity
  • bool is value cached
  • int is value and literal cached
  • float is literal cached
  • complex is literal cached
  • str is literal cached and immutable in content and size
  • list is indexable and mutable
  • tuple is indexable and immutable in content and size
  • one-element tuples must have a trailing comma
  • set is iterable, not indexable, not ordered, with hashable, immutable, and unique keys
  • dict is iterable, not indexable, not ordered, with hashable, immutable, and unique keys, and mutable values
  • self is not a keyword
  • range() is O(1)
Week #2
Tue, 03 May 2022
Examples: Exercise #3: Notes: References:
Takeaways:
  • for in requires iterables
  • iterables respond to __iter__() which return iterators
  • iterators respond to __next__() which return the next value
  • iterators eventually raise a StopIteration exception
  • in-place operators on mutables change the object
  • in-place operators on immutables create new objects
  • class variables are shared by all instances of a class
  • instance variables are unique to an instance of a class
Thu, 05 May 2022
Examples: Notes: References:
Takeaways:
  • containers have __iter__ but not __next__
  • iterators have __iter__ and __next__
  • __iter__ on iterators returns self
  • iterators exist to enable multiple clients to iterate over the same container at the same time
  • list, set, and dict comprehensions are O(n) and eager
  • generator comprehensions are O(1) and lazy
  • generators are iterators
  • generators capture objects
  • range() behaves like a container
  • map(), filter(), count(), and zip() behave like iterators
Week #3
Tue, 10 May 2022
Examples: Exercise #4: Exercise #5: Examples: Notes: References:
Takeaways:
  • functions with yield create generators
  • classes with __call__ create callable instances
  • functions capture names
Thu, 12 May 2022
Examples: Exercise #6: Examples: Exercise #7: Notes: References:
Takeaways:
  • defaulted arguments must be the trailing arguments
  • pass by position must precede by name
  • iterable unpacking must precede dict unpacking
  • f(*t, **d) will handle any function call
  • decorators enable composition of functionalities
Week #4
Tue, 17 May 2022
Exercise #8: Exercise #9: Notes: References:
Takeaways:
Week #5
Tue, 24 May 2022
Examples: Exercise #10: Notes: References:
Takeaways:

Copyright © Glenn P. Downing, 2000-2022
Updated 24 May 2022