Print Your (Box,Curly, Parentheses) Brackets in Python

Print ‘Curly Brackets’

In Python, you can include curly braces (also known as braces or brackets) in a string by escaping them using a backslash (‘\‘). Though this is old method. You can write curly bracaes normally to print braces. Here’s an example:

Python
print("This is a string with curly braces: {}")

Output:

This is a string with curly braces: {}

Note that if you need to use both the left and right curly braces in the string, you’ll need to escape both of them individually. If you want to print double curly braces:

Python
print("This is a string with both left and right curly braces: {{}}")

Output:

This is a string with both double left and right curly braces: {{}}

Print ‘parentheses’ in a string

In Python, you can include parentheses (also known as round brackets) in a string by simply enclosing them within the string. Here’s an example:

Python
print("This is a string with parentheses: ()")

Output:

This is a string with parentheses: ()

If you need to include a string that itself contains parentheses within the string, you can escape the parentheses using a backslash (‘\‘). You can also print double parentheses:

Python
print("This is a string with escaped parentheses: (())")

Output:

This is a string with escaped parentheses: ()

Print ‘box brackets’ in string

In Python, you can include box brackets (also known as square brackets) in a string by simply enclosing them within the string. Here’s an example:

Python
print("This is a string with box brackets: []")

Output:

This is a string with box brackets: []

If you need to include a string that itself contains box brackets within the string, you can escape the brackets using a backslash (\). Though this is an old method. You can print double box brackets.

Python
print("This is a string with escaped box brackets: [[]]")

Output:

This is a string with escaped box brackets: [[]]
Share The Tutorial With Your Friends
Twiter
Facebook
LinkedIn
Email
WhatsApp
Skype
Reddit

Check Our Ebook for This Online Course

Advanced topics are covered in this ebook with many practical examples.