What is a FOR control structure?
This control structure loops through code for a set number of iterations
What is a major difference between arrays and lists?
Arrays all have to be the same data type.
(other answers can be accepted if I determine so)
Where does indexing start?
0
What is a class?
This is where we specify an object. It is the template for that object type and specifies what the object is (state) and what the object does (behaviour)
Who is almost always at fault for errors?
the programmer
What is an IF control structure?
This control structure proceeds with code so long as a condition is true.
How would you create an array in Python?
import numpy as np
array = np.array([])
What would list[3] equal?
list = ['a','b','c','d','e']
List 3 benefits of classes/objects
What are the three types of errors?
- syntax error
- runtime error
- logical error
What is a WHILE loop?
This control structure loops until the condition is no longer met.
if the array is [1,2,3,4,5,6,7,8,9] what would the value be at array[5]
6
How do you add an element to a list?
list.append()
What is the difference of a class variable and an instance variable?
A class variable will apply to all objects of that class whereas the instance variable is local to each object.
What are the three exception types?
- TypeError
- ValueError
- NotImplementedError
What are two (2) differences between Panda tables and numpy arrays and what is one (1) similarity?
How would you create a multidimensional array?
How would you make a string uppercase and duplicated?
Use mystring = "abcd" as an example
What are the 5 categories of methods in a class?
Receive half points if you can name at least 3.
Give one example of each error type
Any one of the following (for each error)
Syntax errors
• leaving out a keyword
• putting a keyword in the wrong place
• leaving out a symbol, such as a colon, comma or brackets
• misspelling a keyword
• incorrect indentation
• empty block
Runtime errors
• division by zero
performing an operation on incompatible types
using an identifier which has not been defined
accessing a list element, dictionary value or object attribute which doesn’t exist
trying to access a file which doesn’t exist
Logical errors
• using the wrong variable name
• indenting a block to the wrong level
• using integer division instead of floating-point division
• getting operator precedence wrong
• making a mistake in a boolean expression
• off-by-one, and other numerical errors
What is a dictionary, set and tuple?
A dictionary is an unordered set of value-key pairs that can be added to, deleted from and overwritten, so long as the keys remain untouched (immutable).
A set is an unordered, unique collection of data.
A tuple is an immutable list that are usually created by comma separated values
How would you add an element to an array?
a = np.append(a, b)
What would be the resultant string?
name = "John Cleese"
name[0:-1:2]
"Jh le"
What is an example of a class relationship and what does it entail/what is its definition?
Aggregation: one class is declared as a class field with another class ("has-a" but not lifecycle dependant usually)
Composition: one class is included as part of the other class. the included class does not exist without the host class ("has-a"/"whole-part", strong lifecycle dependency)
Inheritance: one class is a descendant of another class ("is-a" relationship, one class is a subclass of another)
Association/Dependency: used to show that one class invokes methods in another but there is no other relationship beyond this.
What is the structure of coding exception handling in a python program
try:
...
raise ValueError(x)
except ValueError as err
print(err)