Watch the video above, then read on for the practical depth and worked examples.
What string concatenation is and why it matters in finance
String concatenation is the process of joining two or more strings into one. In finance work, you do this constantly. A trade confirmation needs a counterparty name, a settlement date, a notional amount, and a status. A market alert combines a ticker, a price level, and a timestamp. A regulatory report sticks together account identifiers, balance figures, and risk metrics. Without string concatenation, you would type each message manually. With it, you build them programmatically from data.
For a treasury analyst or risk team member writing Python, string concatenation is one of the first things you need to master. It is not glamorous. But it is how your code produces the actual text that people read: the email alerts, the settlement instructions, the daily reporting pack.
If you are new to Python, start with our guide to variables and data types before working through the examples here.
The plus operator: simple, readable, and when it falls short
The simplest way to concatenate strings in Python is the plus operator.
counterparty = "JP Morgan"
settlement_date = "2024-01-15"
amount = "1,000,000"
message = "Trade confirmed with " + counterparty + " for settlement on " + settlement_date + " in the amount of " + amount
print(message)
Output:
Trade confirmed with JP Morgan for settlement on 2024-01-15 in the amount of 1,000,000
This works. It is readable at a glance. For single use strings, use it without hesitation.
But the plus operator breaks down quickly. As soon as you have more than a handful of values to join, the code becomes cluttered. Imagine building a trade ticket with ten fields. The line grows long. You start losing track of where one value ends and the next begins. Mental load increases for no good reason.
More importantly, the plus operator creates a new string object in memory each time you use it. If you are looping through thousands of trades, building a message for each one, you are creating thousands of intermediate string objects. That is wasteful.
F strings: the modern way to combine text and variables
F strings (formatted string literals) were introduced in Python 3.6 and are now the standard approach for most concatenation work. They are readable, concise, and fast.
counterparty = "JP Morgan"
settlement_date = "2024-01-15"
amount = 1000000
status = "SETTLED"
message = f"Trade confirmed with {counterparty} for settlement on {settlement_date} in the amount of {amount:,} ({status})"
print(message)
Output:
Trade confirmed with JP Morgan for settlement on 2024-01-15 in the amount of 1,000,000 (SETTLED)
Notice that amount is an integer here, not a string. The f string handles the conversion and even applies formatting: the :, adds thousand separators. You can put any Python expression inside the curly braces, not just variables.
F strings are readable because you read the variable in context. They are also performant. Python compiles them efficiently.
For most finance work, f strings should be your default. Use them for alert messages, report headers, confirmation details, and anything else where you are combining a small number of values with text.
F strings also support formatting logic inline. Dates, amounts, and percentages can be formatted on the fly without a separate step. Learn more about number formatting in our post on Python integers and floats.
The join method: speed and clarity for loops and lists
When you are building a string from a list of items, or looping through many rows, the join method is your tool.
trades = [
{"id": "T001", "amount": 500000, "status": "SETTLED"},
{"id": "T002", "amount": 750000, "status": "PENDING"},
{"id": "T003", "amount": 1200000, "status": "FAILED"},
]
report_lines = []
for trade in trades:
line = f"Trade {trade['id']}: {trade['amount']:,} [{trade['status']}]"
report_lines.append(line)
report = "\n".join(report_lines)
print(report)
Output:
Trade T001: 500,000 [SETTLED]
Trade T002: 750,000 [PENDING]
Trade T003: 1,200,000 [FAILED]
The join method takes an iterable (a list, a tuple, any sequence) and combines all items into a single string with a separator between them. Here, the separator is a newline character \n, so each trade appears on its own line.
A weekly note on treasury, liquidity and practical Python. No spam, unsubscribe any time.
Why is join better than looping with plus? Because it is optimised for exactly this task. If you concatenate with plus inside a loop, Python builds a new string after each iteration. With a thousand trades, that is a thousand string creations. The join method builds the entire result in one go.
# Slower: avoid this pattern with large datasets
report = ""
for trade in trades:
line = f"Trade {trade['id']}: {trade['amount']:,} [{trade['status']}]"
report += line + "\n" # Creates a new string each time
This works for datasets under 100 rows. But when you are processing thousands of rows from a data feed or a regulatory extract, join is measurably faster.
Type errors: the most common mistake when concatenating strings and numbers
This is the mistake that catches most beginners, and it will break your code.
amount = 1000000
message = "Total amount: " + amount
This throws a TypeError: you cannot add a string and an integer. Python will not guess. It will not convert. It will fail.
TypeError: can only concatenate str (not "int") to str
The fix is simple: convert the number to a string first using str(), or use an f string (which does the conversion for you). This behaviour applies to Python 3; older versions handled some implicit conversions differently.
# Method 1: explicit conversion
amount = 1000000
message = "Total amount: " + str(amount)
# Method 2: f string (preferred)
message = f"Total amount: {amount}"
In finance work, this mistake is especially common because you are often pulling numbers from databases or calculations. Those numbers are integers or floats. The moment you try to concatenate them with text using plus, you will hit this error.
Use f strings by default. They handle type conversion silently. If you must use plus, remember to call str() explicitly on any non string value.
Building a trade confirmation: a worked example
Let me walk through a realistic scenario. You are building a settlement instruction message from trade data. The message needs to include the trade ID, the settlement date, the counterparty, the amount in the settlement currency, and the instruction status.
from datetime import datetime, timedelta
trade = {
"trade_id": "TRD20240115001",
"counterparty": "Deutsche Bank",
"settle_date": datetime(2024, 1, 17),
"amount": 5500000,
"currency": "EUR",
"status": "READY"
}
instruction_date = datetime.now()
value_date = trade["settle_date"]
days_to_settle = (value_date - instruction_date.date()).days
confirmation = f"""
SETTLEMENT INSTRUCTION
Trade ID: {trade['trade_id']}
Counterparty: {trade['counterparty']}
Value Date: {value_date.strftime('%d %b %Y')}
Amount: {trade['amount']:,.2f} {trade['currency']}
Status: {trade['status']}
Days to settle: {days_to_settle}
"""
print(confirmation)
Output:
SETTLEMENT INSTRUCTION
Trade ID: TRD20240115001
Counterparty: Deutsche Bank
Value Date: 17 Jan 2024
Amount: 5,500,000.00 EUR
Status: READY
Days to settle: 2
This uses an f string with a multi line literal. Notice:
- Dates are formatted using
strftime()inline within the f string - The amount uses
:,.2fto add thousand separators and show exactly two decimal places - Dictionary values are accessed directly inside the curly braces
- The result is readable and maintainable
If you need to send this as an email body or a message to a trading system, you have it in one string. No manual assembly. No copy paste errors. Save this template as a reusable function if you generate multiple confirmations.
Performance: when concatenation method actually matters
For small strings and one time operations, performance is irrelevant. F strings and plus are both fast enough.
Performance matters when you loop. Here is a rough comparison using 10,000 trades:
import time
trades = [{"id": f"T{i:05d}", "amount": i * 1000, "status": "SETTLED"} for i in range(10000)]
# Method 1: plus in a loop (slower)
start = time.time()
result = ""
for trade in trades:
result += f"Trade {trade['id']}: {trade['amount']:,}\n"
elapsed_plus = time.time() - start
# Method 2: join (faster)
start = time.time()
lines = [f"Trade {trade['id']}: {trade['amount']:,}" for trade in trades]
result = "\n".join(lines)
elapsed_join = time.time() - start
print(f"Plus method: {elapsed_plus:.4f}s")
print(f"Join method: {elapsed_join:.4f}s")
On a typical machine, join will be noticeably faster. The larger your dataset, the bigger the gap. CPython 3.9 and above optimise f strings heavily, so the comparison changes slightly depending on your Python version and implementation. For regulatory reporting or high volume data processing, this matters.
If you are processing large datasets regularly, use your IDE's built in profiler to find the bottlenecks. Often, string concatenation is not the problem. But when it is, join is the answer.
Practical takeaway: which method to reach for
Here is your decision tree:
Use f strings when you are building a single message or a small number of strings. They are readable, modern, and fast enough. This covers alert messages, trade confirmations, report headers, and most day to day work.
Use join when you are combining many items from a list or loop, especially if the list has more than 50 items. Build the list of strings first, then join them once.
Avoid the plus operator unless you have only two or three pieces to join. It becomes unreadable and inefficient fast.
Always watch your types. If you are joining strings and numbers, use f strings (they convert automatically) or call str() explicitly. Do not rely on implicit conversion.
String concatenation is a foundation skill. You will use it in every finance Python script you write. Master these patterns now, and you will save yourself debugging time and write cleaner code from the start.

The Complete Python Course
Welcome to the most practical and beginner friendly Python Bootcamp Course on YouTube.
Take the courseGet the next one in your inbox
A weekly note across Finance & Treasury, Innovation & Automation and Career Development. No spam, unsubscribe any time.
Notes across finance and treasury, innovation and automation, and career development, written by practitioners who do the work.
