Skip to content

Reference

This part of the project documentation focuses on an information-oriented approach. Use it as a reference for the technical implementation of the python_template project code.

Python template package.

placeholder

Placeholder file to provide several sample math calculations.

This module allows the user to make mathematical calculations. Adapted from: https://realpython.com/python-project-documentation-with-mkdocs/

Examples:

>>> from python_template import placeholder
>>> placeholder.add(2, 4)
6.0
>>> placeholder.multiply(2.0, 4.0)
8.0
>>> from python_template.placeholder import divide
>>> divide(4.0, 2)
2.0

The module contains the following functions:

  • add(a, b) - Returns the sum of two numbers.
  • subtract(a, b) - Returns the difference of two numbers.
  • multiply(a, b) - Returns the product of two numbers.
  • divide(a, b) - Returns the quotient of two numbers.

add

add(a, b)

Compute and return the sum of two numbers.

Examples:

>>> add(4.0, 2.0)
6.0
>>> add(4, 2)
6.0

Parameters:

Name Type Description Default
a float | int

A number representing the first addend in the addition.

required
b float | int

A number representing the second addend in the addition.

required

Returns:

Type Description
float

A number representing the arithmetic sum result of a and b.

Source code in src/python_template/placeholder.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def add(a: float | int, b: float | int) -> float:
    """Compute and return the sum of two numbers.

    Examples:
        >>> add(4.0, 2.0)
        6.0
        >>> add(4, 2)
        6.0

    Args:
        a: A number representing the first addend in the addition.
        b: A number representing the second addend in the addition.

    Returns:
        A number representing the arithmetic sum result of `a` and `b`.
    """
    return float(a + b)

divide

divide(a, b)

Compute and return the division of two numbers.

Examples:

>>> divide(4.0, 2.0)
2.0
>>> divide(4, 2)
2.0

Parameters:

Name Type Description Default
a float | int

A number representing the first divider in the divide.

required
b float | int

A number representing the second divider in the divide.

required

Returns:

Type Description
float

A number representing the division result of a and b.

Raises:

Type Description
ZeroDivisionError

If b is zero.

Source code in src/python_template/placeholder.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def divide(a: float | int, b: float | int) -> float:
    """Compute and return the division of two numbers.

    Examples:
        >>> divide(4.0, 2.0)
        2.0
        >>> divide(4, 2)
        2.0

    Args:
        a: A number representing the first divider in the divide.
        b: A number representing the second divider in the divide.

    Returns:
        A number representing the division result of `a` and `b`.

    Raises:
        ZeroDivisionError: If `b` is zero.
    """
    if b == 0:
        raise ZeroDivisionError("division by zero")

    return float(a / b)

multiply

multiply(a, b)

Compute and return the multiplication of two numbers.

Examples:

>>> multiply(4.0, 2.0)
8.0
>>> multiply(4, 2)
8.0

Parameters:

Name Type Description Default
a float | int

A number representing the first multiplicator in the multiply.

required
b float | int

A number representing the second multiplicator in the multiply.

required

Returns:

Type Description
float

A number representing the multiplied result of a and b.

Source code in src/python_template/placeholder.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def multiply(a: float | int, b: float | int) -> float:
    """Compute and return the multiplication of two numbers.

    Examples:
        >>> multiply(4.0, 2.0)
        8.0
        >>> multiply(4, 2)
        8.0

    Args:
        a: A number representing the first multiplicator in the multiply.
        b: A number representing the second multiplicator in the multiply.

    Returns:
        A number representing the multiplied result of `a` and `b`.
    """
    return float(a * b)

subtract

subtract(a, b)

Compute and return the substaction of two numbers.

Examples:

>>> subtract(4.0, 2.0)
2.0
>>> subtract(4, 2)
2.0

Parameters:

Name Type Description Default
a float | int

A number representing the first substracter in the substract.

required
b float | int

A number representing the second substracter in the substract.

required

Returns:

Type Description
float

A number representing the substract result of a and b.

Source code in src/python_template/placeholder.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def subtract(a: float | int, b: float | int) -> float:
    """Compute and return the substaction of two numbers.

    Examples:
        >>> subtract(4.0, 2.0)
        2.0
        >>> subtract(4, 2)
        2.0

    Args:
        a: A number representing the first substracter in the substract.
        b:  A number representing the second substracter in the substract.

    Returns:
        A number representing the substract result of `a` and `b`.
    """
    return float(a - b)

scripts

Useful python cli scripts.

placeholder

Useful python cli scripts.

placeholder_script

placeholder_script()

Script that can be run in the command line.

More detail: https://setuptools.pypa.io/en/latest/userguide/entry_point.html

Source code in src/python_template/scripts/placeholder.py
4
5
6
7
8
9
def placeholder_script():
    """Script that can be run in the command line.

    More detail: https://setuptools.pypa.io/en/latest/userguide/entry_point.html
    """
    print("This is a placeholder script that can be run as `entry point`")  # noqa: T201