-2

I could not print the plus sign enclosed in quotation marks.

Tried the following:

print("String Concatenation is done with the "+" sign.")

print("String Concatenation is done with the '"+"' sign.")

print("String Concatenation is done with the "\"+\"" sign.")

print("String Concatenation is done with the "\"+"\" sign.")

print("String Concatenation is done with the """ "+" """ sign.")
marcadian
  • 2,608
  • 13
  • 20
  • 1
    Does this answer your question? [Using quotation marks inside quotation marks](https://stackoverflow.com/questions/9050355/using-quotation-marks-inside-quotation-marks) – slothrop Jul 13 '23 at 14:07

3 Answers3

1

You need to escape the quotation marks like this:

print("String Concatenation is done with the \"+\" sign.")
Patrick F
  • 144
  • 4
1

You can use "\". The sign \ "excludes" the next character if it is quotation marks!

print("\"Hello World\", said Harry")

Another way would be to use ' at the start and beginning:

print('"Hello World", said Harry')
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Harry A.
  • 11
  • 3
-1

After doing other trials-and-errors, finally came up with the right solution:

print("String Concatenation is done with the "'"+"'" sign.")

plus sign should be enclosed in double-single-double quotation marks.

  • 1
    That does work, because in Python you can place string literals next to each other and the parser concatenates them into one literal (https://stackoverflow.com/questions/26433138/what-is-under-the-hood-of-x-y-z-in-python?noredirect=1&lq=1). So your expression equates to `"String Concatenation is done with the "`, followed by `'"+"'`, followed by `" sign."`, and the three are combined by the parser. It works, but the other answers people have posted here are the more conventional ways to handle this. – slothrop Jul 13 '23 at 15:13
  • 1
    It is a solution. But I wouldn't call it "right" but "weird." – Matthias Jul 13 '23 at 15:28
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 16 '23 at 20:59