What makes good programming?
–> more code not necessarily better
What do you use abstraction for in programming?
How do you achieve it?
–> Suppress details
The process of removing details or attributes to focus attention on details of greater importance
Think of a piece of code as a black box and achieve abstraction using functions or docstrings
What do you use decomposition for?
It involves breaking down a complex problem into smaller modules that are easier to understand. The smaller parts are simpler to work with.
Modules should be:
-self contained
-intended to be reused
Achieve decomposition using functions or classes
What are functions?
Functions are reusable pieces of code that have to be called in a program (they do not run automatically)
A function has a name and a body and can have parameters, a docstring
A function should return something
How do you write a function?
def (): body return
How do you invoke a function?
you call it by writing its name with round backets and parameters if needed
i.e. is_even(3)
What is the difference between a formal and a actual parameter?
The formal parameter is the one used i ´n the function definition and the actual one is the one that is called with the function when running –> formal parameter gets found to the value of the actual parameter when function is called
What happens if you do not define a return statement ?
Python automatically returns value None, if no return is given
What is the difference between print and return?
Return:
What are higher-order functions?
Functions that take functions as argument/parameter
What is a list?
A list is a ordered sequence of information accessible by index
How do you iterate through a list L?
for elem in L:
body
How do you access objects (like list instances)?
using the dot (.)
list_name.append(something)
Can you convert a string s into a list L?
Yes, using list(s) –> returns a list with every character from s as an element in L
What is a Tuple?
What are tuples often used for?
What is recursion?
Algorithmically: a way to design solutions to problems by
divide-and-conquer
Semantically: a programming technique where a
function
calls itself
–> must have a base case
What is a dictionary?
They store pairs of data in the form {key : value}
looks up the key –> return value
i.e. grades = {‘Ana’ : ‘B’, ‘John’ : ‘A+’}
grades[‘John’] –> returns ‘A+’
Can values in a dictionary have mutable or immutable types?
Both!
Can Values in dictionaries be duplicates?
Yes
What properties do dictionary keys have?
2. Must be of immutable type (int, float, string, tuple, bool)
What are the differences of lists and values?
Lists:
Dict: