Need help with Python code on an online editor
John_Miller
| Posted in General Questions on
Hey everyone,
I’m working on a Python project using an online editor at <a href=”https://pythononlineeditor.com/”>Python online editor</a>. I’ve run into a problem and could really use some help.
I’m trying to concatenate two strings in Python, but for some reason, my code is not working as expected. Here’s the code snippet I’m working with:
string1 = “Hello”string2 = “World”result = string1 – string2print(result)
I know that string concatenation should use the + operator, but for some reason, I tried using – in the code above, and it’s causing an error. I’ve also tried using +=, but that didn’t work either.
If anyone has experience with this online editor or has any suggestions on how to correctly concatenate strings, I’d greatly appreciate your help!
Thanks in advance!
GBA Detail Library
A collection of one thousand construction details organized by climate and house part
Search and download construction details
Replies
Not sure why you're coming to this particular forum for Python help...
You are indeed correct that using an incorrect syntax will give you an error. The "-" operator is not applicable to strings. The "+" operator (or the "join" function, as in join([s1 s2])) is what you use to concatenate strings.
See https://www.digitalocean.com/community/tutorials/python-string-concatenation for a decent read on string concatenation.
Why do you think that using an incorrect syntax would work when you already know what works?
I strongly suspect this is spam and the linked code editor is malicious
Pretty sure you're right, but hey, we all need to help Nigerian princes get access to their bank accounts...
I wasn't going to feed the spambot, but now I guess it's too late.
I wish there was a "report spam" button.