You want to replace it, not strip it:
s = s.replace(',', '')
Answer from eumiro on Stack Overflow Top answer 1 of 4
178
You want to replace it, not strip it:
s = s.replace(',', '')
2 of 4
21
Use replace method of strings not strip:
s = s.replace(',','')
An example:
>>> s = 'Foo, bar'
>>> s.replace(',',' ')
'Foo bar'
>>> s.replace(',','')
'Foo bar'
>>> s.strip(',') # clears the ','s at the start and end of the string which there are none
'Foo, bar'
>>> s.strip(',') == s
True
csv - Remove comma from middle of string in python - Stack Overflow
My problem is stripping a comma out from a string. This string contains two commas and when this second comma is included in my list of strings, it interferes when writing to a CSV in the proper ma... More on stackoverflow.com
Python: Remove everything after first comma in string
Try .split(",")[0]. More on reddit.com
Efficient Way To Remove Repeating Commas From String
', '.join([x.strip() for x in my_string.split(',') if not x.isspace() and x != '']) More on reddit.com
I must be an idiot or something. Why can't I strip the comma's out of a string?
Maybe you're thinking of split()? test = '12,123,123,123' test2 = test.split(',') test2 ['12','123','123','123'] Concat the elements and the commas are gone :) More on reddit.com
04:26
Python Program #43 - Remove Punctuations From a String in Python ...
03:55
how to remove comma at the end from the below string in python ...
00:54
How to remove punctuation from any string in Python 🐍 #coding ...
Square brackets comma remove from the list array python
03:03
Remove Commas From String Python - YouTube
00:55
Remove Comma from String In Python | Solutions For Python 100 ...
Reddit
reddit.com › r/learnpython › efficient way to remove repeating commas from string
r/learnpython on Reddit: Efficient Way To Remove Repeating Commas From String
December 1, 2022 -
I have a string that consists of something like:
my_string = 'Now is the time, , for all good men, , ,to come to the aid,, of their party'
...and I want to keep only a single comma for each repeating set of commas:
result = 'Now is the time, for all good men, to come to the aid, of their party'
I've looked a numerous methods to remove sequential characters, but 1) these are not sequential (may have one or more blanks between them); and 2) I only want to remove the extra commas and not other repeating characters that might appear in the string.
Any help would be greatly appreciated.
Stack Abuse
stackabuse.com › how-to-remove-commas-from-a-string-in-python
How to Remove Commas from a String in Python
June 12, 2023 - Python's built-in string method replace() is an easy-to-use function for removing characters from a string. The replace() method replaces a specified phrase with another specified phrase, and it's a perfect fit for our problem: # Given string s = "H,e,l,l,o, W,o,r,l,d" # Removing commas from the string s = s.replace(",", "") print(s)
PythonForBeginners
pythonforbeginners.com › home › remove commas from string in python
Remove Commas From String in Python - PythonForBeginners.com
February 9, 2022 - Regular expressions are a great tool to manipulate strings. We can also use them to remove commas from a string in python.
Python Guides
pythonguides.com › remove-commas-from-a-string-in-python
How To Remove Commas From A String In Python?
March 19, 2025 - Read How to Insert a Python Variable into a String? The simplest way to remove commas from a string is by using the built-in replace() method. It allows you to replace a specific substring with another substring or an empty string.
Finxter
blog.finxter.com › home › learn python blog › how to remove a comma from a string? 5 best ways
How to Remove a Comma from a String? 5 Best Ways - Be on the Right Side of Change
May 23, 2022 - This method uses replace() from Python’s built-in string library to remove the comma/commas and return a new string with the modifications made.
Stack Overflow
stackoverflow.com › questions › 59583432 › remove-comma-from-middle-of-string-in-python
csv - Remove comma from middle of string in python - Stack Overflow
The csv module will normally quote strings containing a comma, so you should provide your code to see what is going wrong. replacing the comma isn't the answer. ... You can remove the comma as follows.
Linux Hint
linuxhint.com › remove-string-commas-python
Linux Hint – Linux Hint
November 10, 2021 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
Tutorial Reference
tutorialreference.com › python › examples › faq › python-how-to-remove-commas-from-string
How to Remove Commas from a String in Python | Tutorial Reference
The str.replace() method is the standard, most readable, and efficient way to remove commas or any other substring from a string in Python.
Facebook
facebook.com › groups › python › posts › 1062636001243630
How to remove extra commas from a string in Python
We cannot provide a description for this page right now