Part 4, Organising your python code and data Flashcards
what are the steps in defining a function
this involves
- creating the header
1a. the function name
1b. the functions parameters - create the body, which holds the code the function will execute
what does the python help() function do
this will retrive the header of the function you put in as an argument and also retrive any docstrings held by that function
this is an object (such as an integer or string) that is unchanging and will always stand for itself.
NOTE: A variable is not a literal as it can change value and type at any time
what is a literal
to use these
- place a string surrounded by three quotation marks on each side as the first line of any functions or classes
how do you use docstrings in python
this is an expression constructed using basic expressions
what are constructed expressions
- The right hand side of the assignment is evaluated and an object is created for the expression
- The python interpreter checks to see if any other object is using the same named label
- If the label is not in use then the new label is created and attached to the object
Otherwise
- This label is removed from the object its currently attached to
- The label is then attached to the object that was created in step one
what is the process that python follows when assighning variables
this keyword can be used for debugging and testing purposes
what is the python assert keyword used for
how do you use docstrings in python
to use these
- place a string surrounded by three quotation marks on each side as the first line of any functions or classes
when writing a test function what should be included in the name of the function
- What the function does (a verb such as test)
- What it does it to (such as the function name you are testing)
this is made up of
- Its id
- Its type
- Its value
what three parts is a python object made up of
When the python interpreter reads through the code it will evaluate expressions and data items into objects. These objects are held inside the python interpreters memory
what does the python interpreter do to all data items when reading through the code
name 3 examples of constructed expressions and what they are constructed from
- Lists - constructed using literals
- Arithmetic operators - constructed using literals
- Function expressions - constructed using a function name and arguments
This can be used to find the type of an object
what is the python type() function used for
this will retrive the header of the function you put in as an argument and also retrive any docstrings held by that function
what does the python help() function do
what is text-driven development
This is the idea of writing tests before you write the code. The idea behind this is that it gives you a clearer understanding of what the code should do
- What the function does (a verb such as test)
- What it does it to (such as the function name you are testing)
when writing a test function what should be included in the name of the function
to use a function what 4 things should you know beforehand
- The name of the function
- What kind of arguments it needs
- What it gives back as a return value
- What other effects calling the function has (such as printing to console)
how does the python assert keyword work
this works by creating an assert statement which consists of
- the assert keyword
- a boolean expression
When the boolean expression evaluates to true nothing happens and the program continues running. However if the boolean expression evaluates to false then the program is halted and an assertion error error message is displayed