emma.delia
emma.delia

Reputation: 19

Removing commas at the end of each new line in a string

Assume we have this following string called fruits:

Apple\n,
Orange\n,
Strawberry\n,
Banana\n,
Kiwi\n,

I want to remove all commas from each new line.

The results should look like this:

Apple\n
Orange\n
Strawberry\n
Banana\n
Kiwi\n

Here is my code so far but it is not working:

new_fruits = fruits.replace(',' '')
print(new_fruits)

Upvotes: 0

Views: 171

Answers (1)

MolarFox
MolarFox

Reputation: 87

Looks like you may be mixing syntax from other OO languages

This'll achieve what you're after:

new_fruits = fruits.replace(',', '')

print(new_fruits)

Here're the docs on using replace

Edit to your edit: you're now just missing the comma between the arguments to .replace :)

Upvotes: 1

Related Questions