You want to replace it, not strip it:

s = s.replace(',', '')
Answer from eumiro on Stack Overflow
🌐
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)
Discussions

regex in Python to remove commas and spaces - Stack Overflow
I have a string with multiple commas and spaces as delimiters between words. Here are some examples: ex #1: string = 'word1,,,,,,, word2,,,,,, word3,,,,,,' ex #2: string = 'word1 ... More on stackoverflow.com
🌐 stackoverflow.com
February 28, 2019
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
🌐 r/learnpython
9
2
December 1, 2022
how to remove a space before a comma?
A couple of ways to do it. You can either use formatted strings: print(f"holy shit {name}, your name has {name.lower.count('a')} times the letter a!") (note that you'll need to use apostrophes inside the count method) Or you can use the sep keyword for print: print("holy shit ", name, ", your name has ", name.lower.count("a"), " times the letter a!", sep="") (now you'll need to add the spaces at the end of the strings yourself) More on reddit.com
🌐 r/learnpython
10
1
April 19, 2021
removing whitespace - How can I remove spaces before commas in python without regexes? - Stack Overflow
If, instead, you do print(v+",") then you have no space between the text in v and the comma. More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-remove-spaces-from-a-string
Remove spaces from a string in Python - GeeksforGeeks
Let's look at different methods to do so: To remove all spaces from a string, we can use replace() method. ... Explanation: s.replace(" ", "") replaces every space in s with an empty string "", effectively removing them.
Published: July 11, 2025
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
Master Python string manipulation by learning how to remove whitespace and manage spaces with techniques like strip(), replace(), and regex for cleaner data.
🌐
HackerNoon
hackernoon.com › how-to-remove-commas-from-string-python
How to Remove Commas From String Python | HackerNoon
July 18, 2022 - We use two methods for it, replace() and regex package, both methods are easy to implement in the program. We also see how to remove the n number of commas from the strings using replace function in Python programming with examples and explanation.
🌐
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.

Find elsewhere
🌐
Delft Stack
delftstack.com › home › howto › python › remove commas from string in python
How to Remove Commas From String in Python | Delft Stack
February 2, 2024 - To remove commas from a string in Python, we can use the replace() method or the re package.
🌐
YouTube
youtube.com › watch
How to Remove Commas from a String and Replace with Spaces in Python - YouTube
In this video, we'll explore a common string manipulation task in Python: removing commas from a string and replacing them with spaces. Whether you're cleani...
Published: November 4, 2025
🌐
Jeremy Morgan
jeremymorgan.com › python › how-to-remove-comma-from-string-in-python
How to Remove Comma from String in Python
December 14, 2023 - This will remove all commas from the string and print the result. Regular expressions are a powerful tool for working with text data in Python. You can use them to search for specific patterns, such as commas, and replace them with another value.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › how to remove commas from a string python
How to Remove Commas from a String Python - Spark By {Examples}
November 7, 2024 - How to remove commas from a string in Python? To remove commas from a string you can use multiple approaches of Python. You can use some of the approaches
🌐
Reddit
reddit.com › r/learnpython › how to remove a space before a comma?
r/learnpython on Reddit: how to remove a space before a comma?
April 19, 2021 -

Hi :D

TOTAL noob here.

How to remove a space before a comma? For example here:

name=input("wuts ur name? ")
print("holy shit", name, ",", "your name has", name.lower().count("a"), "times the letter a!")

So for example, if I input "Alexandra", it'll return:

holy shit Alexandra , your name has 3 times the letter a!

but as you can see, there is a space before the comma... how do I remove it? I tried several different things and searched on the internet too, but somehow couldn't find how welp XD

Thanks <3

🌐
AskPython
askpython.com › python › string › strip-last-comma-from-strings
4 Ways to Strip the Last Comma from Strings in Python - AskPython
April 29, 2023 - The original string is= Our text will be here, The final string after removing the last comma is= Our text will be here · Using Replace() Function. This method is another very common method used for stripping strings only up to the required ...
🌐
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
To remove every comma from a string, you simply call .replace() with the comma as the first argument and an empty string as the second. ... If you only want to remove a limited number of commas from the beginning of the string, you can use the optional count argument.
🌐
Facebook
facebook.com › groups › python › posts › 1062636001243630
How to remove extra commas from a string in Python
Popular groups · Find communities for you · Over 1 billion people across the globe are using Facebook Groups to explore their favorite topics · Log in · Categories · Science & tech · Travel · Animals · Sports & fitness · Entertainment
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-remove-all-special-characters-punctuation-and-spaces-from-a-string-in-python
How to remove all special characters, punctuation and spaces from a string in Python?
March 24, 2026 - In this article, we'll explore three effective methods to remove all special characters, punctuation and spaces from strings in Python.
🌐
Mimo
mimo.org › tutorials › python › how-to-remove-spaces-from-a-string-in-python
How to Remove Spaces from a String in Python
What to look for: if results look unchanged, print repr(raw) first. Hidden characters show up as \t (tab) and \n (newline). ... If you want to delete regular space characters (" ") everywhere in the string, use .replace(" ", ""). ... This also removes normal spaces and can feel easier to read.
🌐
Stack Overflow
stackoverflow.com › questions › 74059812 › how-to-remove-brackets-and-commas-from-an-string-input
python - How to remove brackets and commas from an string input? - Stack Overflow
import re s = "[3, 15, 6, 4]" # remove brackets and spaces, or other characters if required replaced = re.sub('[\[\] ]', '', s) # split by comma a = replaced.split(',') b = "" for v in a: b = f'{b}{int(v):x}' print(f'0x{b}') ... import numpy as np s = '[3, 15, 6, 4]' # convert string to array of int values a = np.fromstring(s[1:-1], dtype=int, sep=',') # use built-in formatting option b = np.array2string( a, separator='', formatter={'int': lambda x: f'{x:x}'} )[1:-1] print(f'0x{b}')