Author: Hayden Smith 2021
Why?
What?
Protection from accidental misuse
Protection from deliberate misuse
Static properties can be inferred without executing the code
E.g. pylint statically checks that variables are initialised before they're used
Dynamic properties are checked during execution
E.g. python dynamically checks that an index is inside the bounds of a list and throws an exception if it isn't (unlike an array in C)
animals["fish"]
* mostly
def count(needle, haystack):
'''
Returns the number of copies of integer needle in the list of integers haystack.
'''
copies = 0
for value in haystack:
if needle == value:
copies += 1
return copies
def search(needle, haystack):
'''
Returns the first index of the integer needle in the list of integers haystack.
'''
for i in range(len(haystack)):
if haystack[i] == needle:
return i