reading-notes

Reading 4

  1. What are the key differences between classes and objects in Python, and how are they used to create and manage instances of a class?
    • Objects encapsulate variables and functions into a single entity. They get their variables and functions from classes.
    • Classes are basically a tamplate to create your objects. They define the data and behavior of objects.
  2. Explain the concept of recursion and provide an example of how it can be used to solve a problem in Python. What are some best practices to follow when implementing a recursive function?
    • when a function calls itself this is a technique called recursion.
    • we used recursion in our fibonacci lab def fib(n): if n == 0 or n == 1: return n else: return fib(n - 1) + fib(n - 2)
    • this function runs itself twice in the final line of code (as you can see).
    • if the current problem represents a simple case, solve it. If not, divide iti nto subproblems and apply the same strategy to them.
  3. What is the purpose of pytest fixtures and code coverage in testing Python code? Explain how they can be used together to improve the quality and maintainability of a project.
    • fixtures are functions that are used to setup and tear down test environments and data.
      • make it easier to write & maintain tests
      • share code between tests
      • share a database amongst tests and ensure they are all using consistent data
    • code coverage measures how much of the code is being tested
      • high coverage is important
    • better together: fixtures and coverage
      • quality, maintainability, conficdence

In Class

A staticmethod @staticmethod doesn’t need access to the object properties