close

How to remove parentheses from string

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to remove parentheses from string in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to remove parentheses from string?

  1. How to remove parentheses from string?

    If you simply want to remove all parentheses in the string, use this:

  2. remove parentheses from string

    If you simply want to remove all parentheses in the string, use this:

Method 1

You can try :

>>> import re
>>> document = "(Hello World)"
>>> print(re.sub('[()]', '', document))
Hello World

Method 2

If you simply want to remove all parentheses in the string, use this:

document = '(Hello World)))))(((('
document = re.sub(r'[()]', '', document)
# square brackets, [], will capture anything inside them, in this case, any '(' or ')'

print(document)

Output:

Hello World

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read