The video above shows a quick walkthrough of print in action. Watch it first to see the function in use, then read on for the detail and context you need to apply it effectively in your finance work.
Why print matters in finance coding
You are writing code to calculate a net stable funding ratio or validate cash flow forecasts. Your code runs. Nothing appears. Did it work? What value did it actually compute? You have no idea.
This is where print comes in. Print is your window into what your code is actually doing at each step. In finance work, where a single misplaced decimal or wrong formula can cascade through a report, print is not optional; it is your primary tool for understanding, validating, and trusting your code before it goes into production.
Print is particularly valuable when you are building something new. You are unlikely to get complex logic right on the first attempt. Print lets you check your assumptions at each step. Did that interest rate calculation produce the right number? Did the loop iterate over the right rows? Print tells you. This builds confidence. When you can see the intermediate values, you know what your code is doing.
In a Jupyter notebook (which we recommend for finance work), print output appears immediately below each cell. This makes it ideal for exploring data and testing calculations step by step.
The basic print() syntax
The simplest use of print is to display a single value.
print("Hello, finance")
print(42)
print(3.14159)
Each call outputs one line to the screen. Text goes in quotes. Numbers do not. Variables work too.
rate = 0.045
print(rate)
This outputs 0.045 on its own line. The print function takes whatever you give it and displays it, then moves to the next line automatically.
Displaying multiple values
Often you want to display several values at once. Print handles this cleanly by separating items with spaces.
print("Rate:", 0.045)
print("Notional:", 1000000, "Currency:", "GBP")
Rate: 0.045
Notional: 1000000 Currency: GBP
This works with variables too.
notional = 1000000
rate = 0.045
currency = "GBP"
print("Notional:", notional, "Rate:", rate, "Currency:", currency)
Each comma between items adds a space. This is quick and readable. It is your primary tool for rapid testing and exploration.
String formatting with f-strings
When you need more control over how values appear, f-strings give you clean, readable output. An f-string is a string prefixed with f, and you embed variables inside curly braces.
notional = 1000000
rate = 0.045
currency = "GBP"
print(f"Notional: {notional} Rate: {rate} Currency: {currency}")
F-strings are more readable and flexible than concatenating strings with +. They also let you format numbers precisely.
notional = 1000000
rate = 0.045
print(f"Notional: {notional:,.0f}")
print(f"Rate: {rate:.2%}")
Notional: 1,000,000
Rate: 4.50%
A weekly note on treasury, liquidity and practical Python. No spam, unsubscribe any time.
The :,.0f format specifier means: treat this as a float, display with commas as thousands separators, zero decimal places. The :.2% means: multiply by 100 and add a percent sign, with two decimal places.
In finance work, this is essential. A liquidity coverage ratio or a deposit run off rate needs to appear to the right precision. F-strings let you display numbers the way your reports expect.
lcr = 1.23456
nsfr = 0.87654
print(f"LCR: {lcr:.1%}")
print(f"NSFR: {nsfr:.1%}")
LCR: 123.5%
NSFR: 87.7%
Note: these are illustrative percentages. Real LCR and NSFR calculations involve detailed rules around eligible assets, cash outflow scenarios, and regulatory definitions. The examples here show only the formatting technique.
F-strings are the modern way to format output in Python. Use them instead of older approaches such as the % operator or .format() method.
Controlling output with sep and end
The print function accepts two optional parameters that control how it separates and terminates output: sep and end.
By default, print separates multiple items with a space and ends with a newline. You can change both.
print("2024", "Q1", "Results", sep="-")
2024-Q1-Results
The sep parameter replaces the default space. This is useful for building structured output like CSV or for displaying dates.
The end parameter controls what comes after the output. By default it is a newline, which moves to the next line.
print("Processing", end="...")
print(" done")
Processing... done
By setting end="", the second print continues on the same line. You can set end to any string.
for i in range(5):
print(i, end=" ")
0 1 2 3 4
These parameters are subtle but powerful when you are building output for reports or debugging loops. A common pattern is to print progress indicators without adding newlines.
Print as your debugging tool
The real value of print appears when something is not working. Before you write complex logic, print intermediate values. This habit saves hours.
Imagine you are calculating liquidity coverage and something is wrong. Rather than staring at the formula, print the pieces.
cash_outflows = 1500000
inflows = 1200000
hqla = 2000000
coverage = hqla / (cash_outflows - inflows)
print(f"Cash outflows: {cash_outflows}")
print(f"Inflows: {inflows}")
print(f"Net outflows: {cash_outflows - inflows}")
print(f"HQLA: {hqla}")
print(f"LCR: {coverage:.2%}")
Now you can see each value. If the result is wrong, the output shows you exactly where. Is the net outflow calculation correct? Is the HQLA figure right? Print reveals it immediately.
This is especially useful inside loops or conditionals, where the logic might be subtle.
deposits = [100000, 250000, 500000, 75000]
run_off_rate = 0.10
for i, deposit in enumerate(deposits):
outflow = deposit * run_off_rate
print(f"Deposit {i}: {deposit:,.0f} at {run_off_rate:.0%} = outflow {outflow:,.0f}")
Deposit 0: 100,000 at 10% = outflow 10,000
Deposit 1: 250,000 at 10% = outflow 25,000
Deposit 2: 500,000 at 10% = outflow 50,000
Deposit 3: 75,000 at 10% = outflow 7,500
You can see immediately whether the logic is right. Is the run off rate applying correctly? Are the indices correct? Print answers these questions in seconds. This pattern matters in real PRA reporting work: ILAAP and liquidity stress testing require you to model deposit outflows under stress scenarios. Being able to print and inspect each outflow rate and duration combination before you commit to a forecast saves you from embedding errors in your submissions.
When to stop printing
Print is not permanent. It is for development, testing, and exploration. Remove unnecessary print statements before handing code to production. During development, use it liberally. The few seconds you save by not bothering to print a value will cost you hours when you have to debug by guessing.
In a production script or scheduled report, strip out all exploratory print statements. They slow execution and clutter logs. Keep only the prints that serve a real purpose: progress indicators for long runs, or final results that belong in your output.
Practical takeaway: print before you commit
The habit to build: before you finalise code, print the intermediate values. This is true for:
- Interest rate calculations
- Balance sheet aggregations
- Liquidity forecasts
- Risk metric computations
- Deposit flow projections
Print a few key values. Check them against what you expect. Only once you see the right numbers should you move the code into a function, a script, or a report template.
In a Jupyter notebook this workflow is seamless. Type a line of code, press shift+enter, and see the output instantly. Type a print statement, press shift+enter again. Validate. Adjust. Repeat until it is right.
Print is simple. It is not fancy. But it is the foundation of every finance coder's toolkit. Master it early, and you will write better code, faster, with fewer mistakes.
Get the next one in your inbox
A weekly note across Finance & Treasury, Innovation & Automation and Career Development. No spam, unsubscribe any time.
Notes on treasury, liquidity, banking and regulatory reporting, written by practitioners who do the work.
