Nate Brunelle Today: Style, Collections CS1110 Nate Brunelle Today: Style, Collections
Questions?
Last Time Debugging Slicing
Style You should write code to be read by humans Docstrings Names Pep8 Have information at beginning of functions to describe what it does Names A name should describe the meaning Can be hard Make sure there is one meaning per variable Pep8 Other Python style guidelines Talks about things that aren’t names or docstrings, but make code ugly
Collections Order doesn’t matter, No Repetition Order Matters, Repetition ok Examples: String List Tuple Range Counting starts at 0 collection[index] gives a specific value in the collection Order doesn’t matter, No Repetition Examples: Set Dict
Ordered Collections Collection What it can hold Syntax to create Mutable? String characters ‘’ immutable Range ints range Tuple Anything ( , ) List [ , ] mutable
Methods that Mutate Lists append(element) remove(element) pop(i)