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!

-
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Python,
- Python: Convert Date to DateTime
- How to sort a List using Lambda in Python
- Python matplotlib segmentation fault: 11 macOS Big Sur
- What is Terminal Velocity and its Formula? How to calculate it programmatically?
- How to install Python 3.11 on Mac
- How to flatten a nested list in Python
- Python: Pandas Merge DataFrames on Index Example
- How to Run all Cells at Once Jupyter Notebook
- Python - Convert float to String
- How to add borders to tkinter label text
- How to Exit a Loop in Python Code
- [Python] Fix: ValueError: All arrays must be of the same length
- Sorting an array using Bubble Sort in Python Programming
- How to Unzip a file using Python
- Python: Merge DataFrames Pandas Outer Join Example
- Change label (text) color in tkinter
- Convert Float to String in Python
- Fix: fatal error: No such file or directory compilation terminated
- Python: Access index/counter of a for loop iteration
- Import Other Python Files Examples
- How to install Anaconda on Mac (M1/M2 Mac)
- Python Regular Expression to Find All Matches in List
- How to Read a binary File with Python
- How to disable warnings while Python file execution
- Know current Python Version
More Posts:
- JSP Hello World Program Tutorial with Eclipse and Tomcat Server - Java
- SharePoint Server 2016 error Microsoft Office Online Server 2016 cant be installed on the same machine as a Microsoft SharePoint Server product - SharePoint
- Alternatives for Notepad++ on Mac in 2021 - NotepadPlusPlus
- [fix] The declared package does not match the expected package - Java
- How to view the Eclipse error log - Eclipse
- Android : Error in http connection java.net.SocketException: Permission denied - Android
- Create Bootstrap carousel slider with Text - Bootstrap
- Git Config Command - A Deep Dive - Git