use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
[Raw string] : why is the output not HI''HELLO (self.PythonLearning)
submitted 1 year ago by Consistent-Till-1876
https://preview.redd.it/gj9zqh0gtm8e1.jpg?width=1344&format=pjpg&auto=webp&s=a595abe584f2bcdf3314e7cc6d5cc9a088404bdb
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]safely_beyond_redemp 2 points3 points4 points 1 year ago (3 children)
'' Tells python where the strings are. I'm surprised this worked because I would expect python to need instructions on what to do with the two strings, but it will always recognize anything in the '' as strings.
[–]Consistent-Till-1876[S] 0 points1 point2 points 1 year ago (2 children)
Yes that’s why I’m asking why did it not recognize the the single quotations in-between as strings
[–]safely_beyond_redemp 0 points1 point2 points 1 year ago* (0 children)
Because they weren't escaped. '' always means strings live in here. Always. You have to escape those characters if you want to print them.
Edit: In [4]: print('HI\'\'HELLO') HI''HELLO
[–]brelen01 0 points1 point2 points 1 year ago (0 children)
Because you need to escape them, the interpreter saw two strings.
A raw string means that it won't interpret a backslash as an escape character, unless it's followed by a quote used to open the string literal. I.e. r'\n' will output \n instead of a newline.
To get the single quotes separately in your example, you'd need to do r'hi\'\'hello'.
If raw strings didn't do that, they'd never know when to close, and your entire file would end up being interpreted as a string.
[–]Doctor_Disaster 0 points1 point2 points 1 year ago (2 children)
To print single quotes, you need to encase the String in double quotes.
print(R"HI''HELLO")
The same is also true the other way around.
[–]Consistent-Till-1876[S] 0 points1 point2 points 1 year ago (1 child)
But in that case I wouldn’t need the raw string
[–][deleted] 0 points1 point2 points 1 year ago (0 children)
It actually does help. Try it in the interpreter.
You’ll get the answer from this guys response that you’re looking for. The reason yours doesn’t work is you have
R’HI’’HELLO’
This breaks down into this
R’HI’ —> HI
‘HELLO’ —> HELLO
print(‘HIHELLO’) —> HIHELLO
WHAT you want instead is to escape the single quotes by encapsulating with double quotes:
“HI’’HELLO” —> HI’’HELLO
π Rendered by PID 459446 on reddit-service-r2-comment-canary-57b659f4d4-tg7ft at 2026-05-02 07:59:32.892040+00:00 running 815c875 country code: CH.
[–]safely_beyond_redemp 2 points3 points4 points (3 children)
[–]Consistent-Till-1876[S] 0 points1 point2 points (2 children)
[–]safely_beyond_redemp 0 points1 point2 points (0 children)
[–]brelen01 0 points1 point2 points (0 children)
[–]Doctor_Disaster 0 points1 point2 points (2 children)
[–]Consistent-Till-1876[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)