reading-notes

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 are an encapsulation of variables and functions into a single entity. Objects get their variables and functions from classes.
Classes are essentially a template to create your objects.

  1. assigin class to object
  2. passing to class variables and functions using ( DOT notation)

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?

A recursive function is a function defined in terms of itself via self-referential expressions.

Behind the scenes, each recursive call adds a stack frame (containing its execution context) to the call stack until we reach the base case. Then, the stack begins to unwind as each call returns its results:

def factorial_recursive(n):
# Base case: 1! = 1
if n == 1:
    return 1

# Recursive case: n! = n * (n-1)!
else:
    return n * factorial_recursive(n-1)

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.

Pytest fixtures allow you to set up and tear down test objects or data before and after running tests. Fixtures are functions that return data, objects or resources that are needed for tests, and can be used across multiple tests.

Code coverage is a measure of the amount of code that has been executed during the testing process. It can help identify untested or under-tested areas of your codebase, which can help improve the quality and reliability of your code.

using pytest fixtures and code coverage together can help you write more maintainable, reliable, and efficient tests, which can lead to higher-quality Python projects.

When used together, pytest fixtures and code coverage can help improve the quality and maintainability of your Python projects by providing a standardized way of creating test data and ensuring that your tests cover as much of your codebase as possible.