Skip to content

API Reference

Auto-generated code documentation.

pro_analytics_02

demo_module_basics

Demonstrate Python basics for professional analytics.

This module demonstrates fundamental Python concepts essential for data analysts, including imports, variables, functions, and function calls.

Module Information
  • Filename: demo_module_basics.py
  • Module: demo_module_basics
  • Location: src/pro_analytics_02/
Key Concepts
  • Module imports and code organization
  • Variable declaration and scope
  • Function definition (reusable logic)
  • Function invocation and returns
Professional Applications
  • Building maintainable analytics pipelines
  • Creating reusable analysis functions
  • Organizing code for team collaboration
  • Setting up logging for production debugging

demo_basics

demo_basics() -> None

Demonstrate Python basics.

Source code in src/pro_analytics_02/demo_module_basics.py
127
128
129
130
131
132
133
134
135
136
def demo_basics() -> None:
    """Demonstrate Python basics."""
    logger.info("Starting demo_python() function.")
    show_naming_and_comments()
    show_variables_and_types()
    show_functions_and_fstrings()
    show_builtins_example()
    show_truths()
    logger.info("Experiment with this demo script to learn the basics quickly.")
    logger.info("Exiting demo_python() function.")

main

main() -> None

Entry point when running this file as a Python script.

Arguments: None (nothing is passed in the parentheses after the main).

Returns: None (nothing is returned when this function runs).

This function creates what we call side effects - it just logs output to the console and a file.

Use the logger variable to call info() methods to log messages. Call the log_header() function once to log some key details that can help with debugging. Call the get_summary() function to get the formatted summary string, Log the summary string we get back from get_summary().

Source code in src/pro_analytics_02/demo_module_basics.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
def main() -> None:
    """Entry point when running this file as a Python script.

    Arguments: None (nothing is passed in the parentheses after the `main`).

    Returns: None (nothing is returned when this function runs).

    This function creates what we call `side effects` -
    it just logs output to the console and a file.

    Use the logger variable to call info() methods to log messages.
    Call the log_header() function once to log some key details that can help with debugging.
    Call the get_summary() function to get the formatted summary string,
    Log the summary string we get back from get_summary().
    """
    logger.info("=================")
    log_header(logger, "Professional Python")
    logger.info("=================")

    logger.info("START main()")

    demo_basics()

    logger.info("END main()")

show_builtins_example

show_builtins_example() -> None

Show some Python built-in functions.

Arguments: None - nothing is passed in via the parentheses. Returns: None

Source code in src/pro_analytics_02/demo_module_basics.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
def show_builtins_example() -> None:
    """Show some Python built-in functions.

    Arguments: None - nothing is passed in via the parentheses.
    Returns: None
    """
    logger.info("Python has many built-in functions, like min(), max(), and len().")
    numbers = [1, 2, 3]
    minimum = min(numbers)
    maximum = max(numbers)
    count = len(numbers)
    logger.info(f"For the list of numbers: {numbers}")
    logger.info(f"  The minimum value is min(numbers): {minimum}")
    logger.info(f"  The maximum value is max(numbers): {maximum}")
    logger.info(f"  The length of the list is len(numbers): {count}")

show_functions_and_fstrings

show_functions_and_fstrings() -> None

Show Python functions and f-strings (formatted strings).

Arguments: None - nothing is passed in via the parentheses. Returns: None

Source code in src/pro_analytics_02/demo_module_basics.py
81
82
83
84
85
86
87
88
89
90
91
92
def show_functions_and_fstrings() -> None:
    """Show Python functions and f-strings (formatted strings).

    Arguments: None - nothing is passed in via the parentheses.
    Returns: None
    """
    logger.info("Functions in Python are blocks of reusable code.")
    logger.info("You can call a function by using its name followed by parentheses.")
    logger.info("We use f-strings to combine text and values in Python.")
    logger.info(
        "  Put the 'f' immediately before the opening quote of the string text."
    )

show_naming_and_comments

show_naming_and_comments() -> None

Show Python naming and comments.

Arguments: None - nothing is passed in via the parentheses. Returns: None

Source code in src/pro_analytics_02/demo_module_basics.py
48
49
50
51
52
53
54
55
56
57
58
def show_naming_and_comments() -> None:
    """Show Python naming and comments.

    Arguments: None - nothing is passed in via the parentheses.
    Returns: None
    """
    logger.info("Name Python files with lowercase and underscores.")
    logger.info("In Python, comments start with a '#' symbol and are not executed.")
    logger.info(
        "Comments can also be wrapped in triple single quotes or triple backticks."
    )

show_truths

show_truths() -> None

Show that Python is case-sensitive and indentation matters.

Arguments: None - nothing is passed in via the parentheses. Returns: None

Source code in src/pro_analytics_02/demo_module_basics.py
112
113
114
115
116
117
118
119
120
121
def show_truths() -> None:
    """Show that Python is case-sensitive and indentation matters.

    Arguments: None - nothing is passed in via the parentheses.
    Returns: None
    """
    is_important: bool = True
    logger.info(f"In Python, indentation matters = {is_important}!")
    logger.info(f"In Python, spelling matters = {is_important}!")
    logger.info(f"In Python, uppercase/lowercase matters = {is_important}!")

show_variables_and_types

show_variables_and_types() -> None

Show Python variables and variable types.

Arguments: None - nothing is passed in via the parentheses. Returns: None

Source code in src/pro_analytics_02/demo_module_basics.py
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def show_variables_and_types() -> None:
    """Show Python variables and variable types.

    Arguments: None - nothing is passed in via the parentheses.
    Returns: None
    """
    logger.info("Variables are used to store values.")
    logger.info("Type hints are optional but recommended for clarity.")
    logger.info("  example_number = 42")
    logger.info("  count: int = 42")
    logger.info("  temp_F: float = 42.2")
    logger.info('  user_name: str = "Data Analyst"')

    example_number = 42
    count: int = 42
    temp_f: float = 42.2
    user_name: str = "Data Analyst"
    logger.info(f"Result: {example_number=}, {count=}, {temp_f=}, {user_name=}.")