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
how to remove the commas from a strings that contains commas in a list (Python) - Stack Overflow
This is just one line of a file that reads a list of numbers. I need to remove the commas in the numbers. These numbers are already strings. I am having trouble figuring out how to write this. ['0'... 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
01:27
How to Remove Comma from Substring in Python - YouTube
03:55
how to remove comma at the end from the below string in python ...
04:26
Python Program #43 - Remove Punctuations From a String in Python ...
05:17
square brackets comma remove from the list array 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.
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.
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.
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.
CSDN
devpress.csdn.net › python › 62f4e2bbc6770329307fa7a8.html
How to Remove Commas From String Python_python_Mangs-Python
August 11, 2022 - We will use replace the () function to remove all commas from the string. replace() is an in-built function in Python, where replace() function is used to replace any characters from the given strings or is used to replace all occurrences of a substring from another substring.
Stack Overflow
stackoverflow.com › questions › 72496206
how to remove the commas from a strings that contains commas in a list (Python) - Stack Overflow
If the string doesn't contain ,, replace() will just return it unchanged. ... To modify the array value in place, you have to re-assign it. The below function illustrates how to do so. def remove_commas(array): for i in range(len(array)): if ',' in array[i]: array[i] = array[i].replace(',', '') return array
YouTube
youtube.com › techniquecoding
Remove Commas From String Python - YouTube
Python has a number of built-in functions that assist the users in executing different string manipulations. The replace() function is among the built-in fun...
Published October 20, 2022 Views 1K