Week II Cheat Sheet
Dictionary
Python dictionaries store objects by key (instead of positions like list or tuple), and map keys to associated values. We can index the dictionary by key to fetch and change the keys’ associated values. It's very similar to python list, but the item in the square brackets is a key, not a relative position.
Function
Functions are reusable pieces of programs. They allow you to give a name to a block of statements, to run that block using the specified name anywhere in your program and any number of times. This is known as calling the function.
Functions are defined using the def
keyword. After this keyword comes an identifier name for the function, followed by a pair of parentheses which may enclose some parameters, and by the final colon that ends the line. Next follows the block of statements that are part of this function.
The return
statement is used to return from a function i.e. break out of the function. We can optionally return a value from the function as well.
pass
is a null operation -- when it is executed, nothing happens. It is useful as a placeholder when a statement is required syntactically, but no code needs to be executed. It is useful when you have started writing your function but have not finished it yet.
Last updated