Part 4, Organising your python code and data Flashcards

1
Q

what are the steps in defining a function

A

this involves

  1. creating the header
    1a. the function name
    1b. the functions parameters
  2. create the body, which holds the code the function will execute
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does the python help() function do

A

this will retrive the header of the function you put in as an argument and also retrive any docstrings held by that function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

what is a literal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

to use these

  1. place a string surrounded by three quotation marks on each side as the first line of any functions or classes
A

how do you use docstrings in python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

this is an expression constructed using basic expressions

A

what are constructed expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. The right hand side of the assignment is evaluated and an object is created for the expression
  2. The python interpreter checks to see if any other object is using the same named label
  3. If the label is not in use then the new label is created and attached to the object

Otherwise

  1. This label is removed from the object its currently attached to
  2. The label is then attached to the object that was created in step one
A

what is the process that python follows when assighning variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

this keyword can be used for debugging and testing purposes

A

what is the python assert keyword used for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

how do you use docstrings in python

A

to use these

  1. place a string surrounded by three quotation marks on each side as the first line of any functions or classes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

when writing a test function what should be included in the name of the function

A
  1. What the function does (a verb such as test)
  2. What it does it to (such as the function name you are testing)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

this is made up of

  1. Its id
  2. Its type
  3. Its value
A

what three parts is a python object made up of

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

what does the python interpreter do to all data items when reading through the code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

name 3 examples of constructed expressions and what they are constructed from

A
  1. Lists - constructed using literals
  2. Arithmetic operators - constructed using literals
  3. Function expressions - constructed using a function name and arguments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

This can be used to find the type of an object

A

what is the python type() function used for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

this will retrive the header of the function you put in as an argument and also retrive any docstrings held by that function

A

what does the python help() function do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is text-driven development

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. What the function does (a verb such as test)
  2. What it does it to (such as the function name you are testing)
A

when writing a test function what should be included in the name of the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

to use a function what 4 things should you know beforehand

A
  1. The name of the function
  2. What kind of arguments it needs
  3. What it gives back as a return value
  4. What other effects calling the function has (such as printing to console)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

how does the python assert keyword work

A

this works by creating an assert statement which consists of

  1. the assert keyword
  2. 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  1. Lists - constructed using literals
  2. Arithmetic operators - constructed using literals
  3. Function expressions - constructed using a function name and arguments
A

name 3 examples of constructed expressions and what they are constructed from

20
Q

what is the python assert keyword used for

A

this keyword can be used for debugging and testing purposes

21
Q

This can be used to find the id of an object

A

what is the python id() function used for

22
Q

this is the parts that you know about, including

  1. name
  2. arguments
  3. return values
  4. any other effects/actions
A

explain the concept of a function interface

23
Q

what are these known as

1. variables

2. literals

A

name 2 objects that are considered basic expressions

24
Q

explain the concept of the function implementation

A

This is everything that goes on under the bonnet, it is not important to know what happens here just that you understand the interface

25
these are known as containers and the value of a container will consist of zero or more references or labels. Each reference or label is then attached to an element of the list such as a string or integer
what are lists in python known as and what will a list contain as it values
26
what is a **literal**
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
27
1. The name of the function 2. What kind of arguments it needs 3. What it gives back as a return value 4. What other effects calling the function has (such as printing to console)
to use a function what 4 things should you know beforehand
28
what is the **python type() function** used for
This can be used to find the type of an object
29
this is a way that python helps you to document your code
what is a docstring in python
30
explain the concept of a **function interface**
this is the parts that you know about, including 1. name 2. arguments 3. return values 4. any other effects/actions
31
what are lists in python known as and what will a list contain as it values
these are known as containers and the value of a container will consist of zero or more references or labels. Each reference or label is then attached to an element of the list such as a string or integer
32
what is a docstring in python
this is a way that python helps you to document your code
33
what three parts is a **python object** made up of
this is made up of 1. Its id 2. Its type 3. Its value
34
when using a **function** what are its three parts
this is made up off 1. a name 2. any arguments 3. expression (the combination of the name and any arguments)
35
what does the python interpreter do to all data items when reading through the code
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
36
in python what are data items such as strings or integers known as
these are known as objects
37
this is made up off 1. a name 2. any arguments 3. expression (the combination of the name and any arguments)
when using a **function** what are its three parts
38
name 2 objects that are considered **basic expressions**
what are these known as ## Footnote **1. variables** **2. literals**
39
what is the **python id() function** used for
This can be used to find the id of an object
40
what are **constructed expressions**
this is an expression constructed using basic expressions
41
these are known as objects
in python what are data items such as strings or integers known as
42
this works by creating an assert statement which consists of 1. the assert keyword 2. 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
how does the python **assert** keyword work
43
what is the process that python follows when assighning variables
1. The right hand side of the assignment is evaluated and an object is created for the expression 2. The python interpreter checks to see if any other object is using the same named label 3. If the label is not in use then the new label is created and attached to the object Otherwise 1. This label is removed from the object its currently attached to 2. The label is then attached to the object that was created in step one
44
This is everything that goes on under the bonnet, it is not important to know what happens here just that you understand the interface
explain the concept of the **function implementation**
45
this involves ## Footnote 1. creating the header 1a. the function name 1b. the functions parameters 2. create the body, which holds the code the function will execute
what are the steps in **defining a function**
46
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 is **text-driven development**