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
Yeah, although I′m all for operator overloading when it makes sense (I really like how livescript handles a/b with a and b strings by making it do a.split(b), and a*b with a a list and b a string by making it do b.join(a)), it's quite difficult for substraction to be meaningful with a and b strings
113
u/Bainos Nov 07 '20
"Hello World!" - "World!" + "Bro!"