-1

I have recently started python and am having a frustratingly hard time trying to figure out how to print a raw string containing both ' and " characters. Even with various combinations of r'' and \ I cannot get python to return the literal string that I require.

Goal: Assign string of the following format to variable (similar format to be used as password). String: "1z8'aoVz1+9p}2C (16 character string starting with " and containing ').

Current result:

>>> string ='''"1z8'aoVz1+9p}2C'''
>>> string
    '"1z8\'aoVz1+9p}2C'

>>> string =r'"1z8\'aoVz1+9p}2C'
>>> string
    '"1z8\\\'aoVz1+9p}2C'

I have also tried splitting it into several variable and concatenating but python always returns the \ before '.

Thank you all for your help. I have learn a lot from this forum.

massey95
  • 11
  • 1

1 Answers1

0

There is no need for raw string:

string =""""1z8'aoVz1+9p}2C"""

Now, if you do this:

>>> string =""""1z8'aoVz1+9p}2C"""
>>> string

you will get this:

'"1z8\'aoVz1+9p}2C'

but if you print it, you'll get what you want:

"1z8'aoVz1+9p}2C
xilpex
  • 2,716
  • 2
  • 10
  • 38