layout: true
Class 8: Python
--- class: center, middle # Python ### Class 8 --- # Overview 1. Announcements 2. Review 3. Q&A 4. Basic assignment --- # Announcements * Make assignments due March 20 * Python assignments due March 27 --- # Review * Python is a fairly intuitive language, I'll focus on quirks * Mutability * Real and floor division * Comprehensions * Keyword args * Class definitions * Dunder methods --- # Review ## Mutability --- # Review ## Real and floor division * Real division: `/` * Floor division: `//` --- # Review ## Comprehensions * List * `[ x.attr for x in l ]` * Set * `{ x.attr for x in l }` * Dictionary * `{ k:v*2 for k, v in d.items() }` * Can have conditions * `[ x.attr for x in l if x.cond() ]` --- # Review ## Keyword args * `somefunc(somearg=3, anotherarg=5)` --- # Review ## Class definition * `__init__(self, ...)` function as "constructor" --- # Review ## Dunder methods * Special methods that start and end with `__` * Provide ability to implement underlying behavior of various operations * Examples: * `__add__` * `__truediv__` * `__getitem__` * https://docs.python.org/3/reference/datamodel.html#special-method-names --- class: center, middle # Q&A --- class: center, middle # Basic assignment