String formatting in Python means creating text that includes dynamic values such as numbers, names, dates, or calculated results. It is used heavily in data analysis because you often need to generate readable outputs like summary sentences, file names, chart titles, logging messages, and report lines. Instead of manually typing values into text, you format strings so Python automatically inserts the correct values.
The most common and clean method is f-strings. With f-strings, you write an f before the quotation marks and place variables inside curly braces. This is simple to read and works well when you are combining multiple values in one message. For example, you can create output like “Total sales in 2025: 125000” by inserting the total_sales variable into the string. F-strings also allow formatting rules, which is useful in analysis. You can control decimal places for floats, add commas for large numbers, show percentages, and control alignment. For instance, you may want a number like 1234567.89 to display as 1,234,567.89, or a value like 0.357 to display as 35.70%.
Another approach is the format() method, where you use placeholders {} and then pass values into format(). This is useful when you want to reuse a template string or when you are working in older codebases. A third, older style is using percent formatting (%), but it is less common today and mainly seen in older Python scripts.
String formatting is also important when building file paths and structured output. For example, you may generate a file name like “report_2026_02.csv” based on a date variable, or create labels like “Region: North, Growth: 8.5%” for reporting. In short, string formatting helps you produce clean, professional, and readable output without manual editing, which makes your analysis workflows faster and more reliable.

