HOWTO · Python

How to Add Character to String in Python

This tutorial demonstrates how to add a character to a string in Python.

On this page

To add a character to a string in Python, concatenate it with + or place it in a formatted string. A character is represented by a string containing one character. Because Python strings are immutable, these operations return a new string; they do not change the original. Appending puts text at the end, while inserting at another position requires slicing the original around that position.

Run this example:

message = "Hello"
character = "!"
result = message + character
print(result)

Add a Character to a String in Python Using the + Operator

Use + when the operation is straightforward concatenation. Both operands must be strings. The result is a new string, so message still contains "Hello" after the expression below.

message = "Hello"
character = "!"
result = message + character
print(result)

If the value to add is numeric, convert it to a string first with str(). For example, "Page " + str(3) combines text and a number after conversion. Adding a number directly to a string raises TypeError because the operand types do not match.

For insertion at a known index, combine slices around the insertion point: text[:index] + character + text[index:]. This also creates a new string. Choose an index that is valid for the intended position, and remember that Python string indexes count from zero.

Add a Character to a String in Python Using the join() Method

join() assembles an iterable of strings. The string on which you call the method becomes the separator between each pair of elements; it is not a special append operation. Use an empty separator when joining pieces without extra text between them, or choose a separator such as a comma when that is part of the desired result.

parts = ["red", "green", "blue"]
result = ", ".join(parts)
print(result)

Every element in the iterable must be a string. Convert non-string values before joining, for example with str(value). For a single existing string plus a suffix, + is usually the clearest expression; join() is useful when collecting several pieces, especially when they need a consistent separator.

Add a Character to a String in Python Using the str.format() Method

str.format() places values into curly-brace placeholders. Put the placeholders where the pieces should appear, then pass matching values to the method. Adjacent placeholders concatenate directly, so no separator is added unless you include one in the template.

name = "Ada"
punctuation = "!"
result = "Hello, {}{}".format(name, punctuation)
print(result)

This approach works in Python versions that support str.format() and is useful when a template should be separate from the values. For more than one placeholder, provide values in the same order, or use named placeholders such as "Hello, {name}!".format(name="Ada") to make the relationship explicit.

Add a Character to a String in Python Using String Interpolation (f-strings)

f-strings provide a concise way to embed values and expressions in string literals. They require Python 3.6 or later. Place each variable or expression inside braces after the f prefix.

name = "Ada"
punctuation = "!"
result = f"Hello, {name}{punctuation}"
print(result)

Use an f-string when its inline template is easy to read. The inserted value is converted to text for display in the resulting string; the original string and variables remain unchanged. For older Python versions, use str.format() or concatenation instead.

Add a Character to a String in Python Using the % Operator

% string formatting is a legacy alternative. A placeholder such as %s marks where a value belongs, and the operator supplies that value. With multiple placeholders, pass a tuple in matching order.

name = "Ada"
punctuation = "!"
result = "Hello, %s%s" % (name, punctuation)
print(result)

For new code, prefer the formatting style that makes the template easiest to understand. % remains useful when maintaining existing code that already uses this syntax.

Conclusion

Use + for a simple append, str.format() or an f-string to combine text with values, and join() to assemble multiple strings with a separator. Convert numbers to strings before concatenation or joining. In every case, the operation produces a new string, so assign the result if you need to keep it. The examples above are runnable Python snippets; this packet supplies no execution record, so no observed output is claimed here.