You want to replace it, not strip it:

s = s.replace(',', '')
Answer from eumiro on Stack Overflow
๐ŸŒ
Jeremy Morgan
jeremymorgan.com โ€บ python โ€บ how-to-remove-comma-from-string-in-python
How to Remove Comma from String in Python
December 14, 2023 - Here are a few of the most common methods: The replace() method is a simple way to remove commas from strings. It takes two arguments: the first is the string you want to search for, and the second is the string you want to replace it with.
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
How to remove spaces after comma in python? - Stack Overflow
Where according to your question ... by "," (comma). ... Sign up to request clarification or add additional context in comments. ... This is due to your print statement. What you can do is first assign it to a variable, replace the spaces and then print it. The replace and print can be combined since replace returns the new string... More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
pandas - Remove space between string after comma in python dataframe column - Stack Overflow
df1 ID Col 1 new york, london school of economics, america 2 california & washington, harvard university, america Expected output is : df1 ID ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
HackerNoon
hackernoon.com โ€บ how-to-remove-commas-from-string-python
How to Remove Commas From String Python | HackerNoon
July 18, 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 ...
๐ŸŒ
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

Find elsewhere
๐ŸŒ
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)
๐ŸŒ
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.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-remove-spaces-from-a-string
Remove spaces from a string in Python - GeeksforGeeks
If we only want to remove spaces from the beginning of the string, we can use lstrip().
Published ย  July 11, 2025
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-consecutive-pairs-comma-removal
Python โ€“ Consecutive Pairs comma removal | GeeksforGeeks
April 4, 2023 - The replace() function is called on the resulting string to remove the commas between each tuple and replace them with a space. This results in the removal of consecutive pairs duplication.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
How to remove extra space from output list tuple? - Python Help - Discussions on Python.org
May 5, 2022 - Hi, I have this input [python]P (0, 2,+1) (2, 0, -1) (0, 4,+1) (4, 0, -1)[/python] and I would like to have it printed out this way [python][(0, 2, 1), (2, 0, -1), (0, 4, 1), (4, 0, -1)][/python]. However, due to the extra space in the input I ran into this error.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-remove-spaces-from-string
Effective Ways to Remove Spaces from Strings in Python | DigitalOcean
July 11, 2025 - Master Python string manipulation by learning how to remove whitespace and manage spaces with techniques like strip(), replace(), and regex for cleaner data.
๐ŸŒ
Intellipaat
intellipaat.com โ€บ community โ€บ 30131 โ€บ split-by-comma-and-strip-whitespace-in-python
Split by comma and strip whitespace in Python - Intellipaat Community
September 17, 2019 - I have some python code that splits on a comma, but doesn't strip the whitespace: >>> string ... a quicker, easier and more elegant way of doing it.