-1

I want to display a rational expression using Python 3. Because it is stored in my variable, it applies the effect of the backslash on my terminal, here is the rational expression I try to display :

struct = "{}\"{}\"{}{}{}"

So what I am trying to find is an expression that prints all the string, including the '\'

3
  • 1
    Try using a raw string by appending r before the opening quote: struct = r"{}\"{}\"{}{}{}". Commented Jan 30, 2023 at 12:36
  • 2
    What do you mean by "rational expression"? As defined, your string does not contain any backslashes; they are consumed during the construction of the string to escape the double quotes. Commented Jan 30, 2023 at 12:49
  • I mean like special characters who have an effect on the string, I kinda confused it with the bash rational expressions. But you are right, I didn't write any backslashes not consumed, all I wanted to do was display the ones who escape the double quote, but now I know that I can do so by typing 'r' just before the opening quote just as said by the comment above. Commented Jan 30, 2023 at 13:54

1 Answer 1

0

You can solve it like this:

struct = '{}\\"{}\\"{}{}{}'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.