r/ProgrammerHumor • • Nov 06 '20

Meme Totally agree

Post image
52.1k Upvotes

474 comments sorted by

View all comments

Show parent comments

71

u/itchy_bitchy_spider Nov 07 '20

Alternatively use replace... Support ed since forever I think lol

"Hello World".replace("World", "Bro")

8

u/[deleted] Nov 07 '20

Yeah I normally use this when I want to replace something in a string. Easy to read and short.

1

u/cheesits456 Nov 07 '20

Thats also valid JavaScript syntax! It only replaces the first instance of "World" though, if you have more than one, you'll need to use a regular expression, like "Hello World".replace(/World/g, "Bro") (idk if python is different in that regard)

Or, if that regular expression is too scary-looking, you could instead do "Hello World".split("World").join("Bro") 😎 /s