GBA Logo horizontal Facebook LinkedIn Email Pinterest Twitter X Instagram YouTube Icon Navigation Search Icon Main Search Icon Video Play Icon Plus Icon Minus Icon Picture icon Hamburger Icon Close Icon Sorted

Community and Q&A

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 – string2  
print(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 Prime

Join the leading community of building science experts

Become a GBA Prime member and get instant access to the latest developments in green building, research, and reports from the field.

Replies

  1. WilliamLi | | #1

    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?

    1. gcmn | | #2

      I strongly suspect this is spam and the linked code editor is malicious

      1. WilliamLi | | #3

        Pretty sure you're right, but hey, we all need to help Nigerian princes get access to their bank accounts...

    2. Expert Member
      DCcontrarian | | #4

      I wasn't going to feed the spambot, but now I guess it's too late.

      I wish there was a "report spam" button.

Log in or create an account to post an answer.

Community

Recent Questions and Replies

  • |
  • |
  • |
  • |