To remove quotes from within a String in Python, we can make use of the functions such as strip(), re and replace().
Example 1: Remove Leading and Trailing Single Quotes using strip()
str_with_single_quotes = "'Hello there! How are you?'"
str_without_single_quotes = str_with_single_quotes.strip("'")
print(str_without_single_quotes)
Output:
Hello there! How are you?
Example 2: Remove Leading and Trailing Double Quotes using regex - re module
import re
str_with_single_quotes = "He said \"I am not coming!\""
str_without_single_quotes = re.sub(r"\"", "", str_with_single_quotes)
print(str_without_single_quotes)
Output:
He said I am not coming!
Example 3: Using replace() function to repalce both single and double quotes
import re
str_with_single_quotes = "\"This isn't mine\""
str_without_single_quotes = str_with_single_quotes.replace("'", "").replace("\"", "")
print(str_without_single_quotes)
Output:
This isnt mine!

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!