Reading
Classes and Objects
- Objects are a group of variables and functions that belong together
- Classes allow you to create your objects
class Dog:
color = "Yellow"
def bark(self):
print("Woof woof!")
pluto = Dog()
You can use dot notation to access variables in the newly created object.
print(pluto.color)
"Yellow"
Assigning variables can be accomplished with init
class NumberHolder:
def __init__(self, number):
self.number = number
def returnNumber(self):
return self.number
var = NumberHolder(7)
print(var.returnNumber()) #Prints '7'
Thinking Recursively
- Reduce problem into simpler instances
- The base case is the most reduced version of the problem
- Thread the ‘state’ through each iteration by passing it to each recursive call
Fixtures
- During testing using pytest, some objects may want to be used throughout all tests. These are fixtures.
- The @pytest.fixture decorator is used on objects you would like to access further in tests