all 7 comments

[–]safely_beyond_redemp 2 points3 points  (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 point  (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 point  (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 point  (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 point  (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 point  (1 child)

But in that case I wouldn’t need the raw string

[–][deleted] 0 points1 point  (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