🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreeHow to Print Brackets in Python?

You are writing a Python program and need to output bracket characters in your output. A user-facing message might need square brackets. A debug statement might need curly braces. The print() function does not make this obvious because brackets also have syntactic meaning in Python.
This tutorial covers every method for printing brackets in Python. You will see direct print() calls, string concatenation, f-strings, the format() method, and the escape sequence approach. Each section explains when to use which method and shows runnable code with actual output.
Quick Summary
Here is the fastest way to print any bracket character in Python. All three types work the same way as any other string. The complexity arises only when you want to embed brackets inside a larger string that also contains other formatting, or when you are building strings dynamically.
print("()") # parentheses
print("[]") # square brackets
print("{}") # curly braces
Printing Parentheses: ()
Parentheses appear in tuples, function calls, and context managers. Printing them is straightforward, but the story changes when you want to build a string that contains parentheses alongside other content.
Direct print with quotes
The simplest approach wraps the brackets in a string and passes it to print().
print("(")
print(")")
print("()")
Output:
(
)
()
Each call outputs one line. This works for any bracket type.
Using an f-string
F-strings were added in Python 3.6. They offer the cleanest syntax for embedding brackets in formatted output.
name = "closure"
result = f"Function {name} uses parentheses like this: ({name})"
print(result)
Output:
Function closure uses parentheses like this: (closure)
F-strings handle mixed content naturally. You embed variables with {variable} and plain text stays as literal characters. No escape sequences needed.
Using the format() method
The format() method works across Python versions and is useful when you need precise control over the output structure.
template = "Position {} holds the value {}"
output = template.format(1, "example")
print(f"Wrapping: ({output})")
Output:
Wrapping: (Position 1 holds the value example)
Building a tuple as a string
Tuples use parentheses in their syntax representation. If you want to print a tuple that looks like (1, 2, 3), you are printing a string that represents a tuple, not an actual tuple object.
values = [1, 2, 3]
tuple_str = "(" + ", ".join(map(str, values)) + ")"
print(tuple_str)
Output:
(1, 2, 3)
String concatenation using + works for building bracket-enclosed representations from dynamic data.
Printing Square Brackets: []
Square brackets denote lists and serve as the indexing operator in Python. Printing them comes up when you are displaying list syntax, writing a parser output, or rendering data in a human-readable format.
Direct print with quotes
The same direct approach works for square brackets.
print("[")
print("]")
print("[]")
Output:
[
]
[]
Printing a list with brackets
When you print a Python list directly, Python shows the brackets because lists use square bracket syntax. This is a natural consequence of how str() converts list objects.
my_list = ['apple', 'banana', 'cherry']
print(my_list)
Output:
['apple', 'banana', 'cherry']
The brackets appear because you are printing the list object directly, not constructing a string representation. If you need custom formatting, use string operations.
Using an f-string with square brackets
items = ["first", "second", "third"]
for i, item in enumerate(items):
print(f"Item [{i}] = {item}")
Output:
Item [0] = first
Item [1] = second
Item [2] = third
This pattern is common in logging and console output where square brackets serve as visual delimiters for indices or labels.
Using string join to build bracket-enclosed output
elements = ["alpha", "beta", "gamma"]
joined = ", ".join(elements)
result = f"[{joined}]"
print(result)
Output:
[alpha, beta, gamma]
The join() method combined with f-string interpolation gives you full control over the bracket placement and the content inside.
Printing Curly Braces: {}
Curly braces create dictionaries and sets. They also appear in f-string placeholders and the format() method. Printing literal curly braces requires escaping them because they have special meaning in string formatting.
The double-brace escape technique
In f-strings and format() strings, a single { starts a placeholder. To print a literal {, you write {{. The same applies to closing braces: }} prints a literal }.
data = {'name': 'Alice', 'age': 30}
print(f"Person: {{'name': '{data['name']}', 'age': {data['age']}}}")
Output:
Person: {'name': 'Alice', 'age': 30}
The {{ and }} syntax is the standard approach for escaping braces in any formatted string in Python.
Using format() with double braces
template = "Dictionary literal: {{{key}: {value}}}"
output = template.format(key="status", value="active")
print(output)
Output:
Dictionary literal: {status: active}
Two opening braces {{ produce one literal opening brace. One {key} interpolates the variable. Two closing braces }} produce one literal closing brace.
Using direct concatenation for curly braces
String concatenation sidesteps the escape problem entirely because concatenation does not interpret format placeholders.
key = "hostname"
value = "server01"
result = "{" + key + ": " + value + "}"
print(result)
Output:
{hostname: server01}
This approach is verbose but eliminates the cognitive overhead of tracking escape sequences.
Printing a dictionary as a string with braces
config = {"port": 8080, "host": "localhost"}
print(config)
Output:
{'port': 8080, 'host': 'localhost'}
Python uses single quotes for string values inside the str() representation of a dictionary. Use json.dumps() if you need double quotes for valid JSON output.
When to Use Each Method
The best method depends on your context. Here is a decision guide.
- Static strings only: Use
print("()"). Plain and fast. - Embedding values: Use f-strings. They are the most readable option for Python 3.6+.
- Dynamic data building: Use string concatenation or
join()with an f-string wrapper. - Old Python versions: Use
format()instead of f-strings for compatibility with Python 2.7 and early Python 3 releases. - Curly braces in format strings: Double them up as
{{and}}. - JSON-like output: Use
json.dumps()which handles all bracket escaping automatically.
Practical Example: Building a Log Message
Here is a complete example that combines all bracket types in a realistic logging scenario.
import json
def log_event(event_type, data):
payload = json.dumps(data)
message = f"[LOG] ({event_type}) payload: {payload}"
print(message)
log_event("user_login", {"user_id": 42, "session": "abc123"})
Output:
[LOG] (user_login) payload: {"user_id": 42, "session": "abc123"}
This demonstrates parentheses for the event type, square brackets for the log label prefix, and curly braces from the JSON output. All three bracket types appear in a single readable output line.
TLDR
- Print brackets as plain strings with
print("()")for simple cases. - Use f-strings for mixed content with variables embedded alongside brackets.
- Escape curly braces in format strings by doubling them:
{{becomes{. - String concatenation with
+sidesteps all escaping and works for building dynamic representations. - Use
json.dumps()to generate JSON output with properly escaped brackets.
Frequently Asked Questions
Q: How do I print brackets without quotes around them?
You do not need quotes around the brackets when passing them to print() because the brackets are part of the string itself. The quotes define the string; the brackets are the content. print("[") outputs the character [ and nothing else.
Q: Why do I need double braces {{ for curly braces in f-strings?
A single { inside an f-string starts a placeholder expression. When you want the literal character { to appear in your output, Python needs you to escape it. Writing {{ tells Python to output one { character.
Q: Can I use triple quotes for bracket strings?
Triple-quoted strings are useful for multiline content. The same bracket escaping rules apply inside them if you are using format() or f-string syntax. For plain triple-quoted strings, brackets are treated as regular characters with no special meaning.
Q: How do I print square brackets in a list without Python adding quotes?
Python adds quotes to string values inside list representations because str() uses Python syntax for the representation. If you want custom formatting, build the output string manually using join() or f-strings as shown in the sections above.
Q: Does this work the same in Python 2.7?
F-strings were introduced in Python 3.6, so they do not work in Python 2.7. For Python 2.7 compatibility, use the format() method or string concatenation instead.


