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

Table of Contents

Related Tutorials

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 (‘\‘). Here’s an example:

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:

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

Output:

This is a string with both 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:

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 (‘\‘):

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:

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 (\):

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

Output:

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