0

I have written the below python program.

var = '28'
express = "r'\b" + var + "\b'"
print(express)

I expected to get r'\b28\b' but I am getting r'28'.

I don't understand why. Can someone please help me with it? Besides var is supposed to be a user input so I need to know some way to print express correctly.

1
  • 2
    Which is to say, concatenation is working fine. The question is, why are you trying to generate this string? Commented Nov 10, 2022 at 21:28

1 Answer 1

1

\b is the escape sequence for backspace. If you want literal \b in your result, use a raw string to prevent the escape sequence from being processed.

var = '28'
express = r"r'\b" + var + r"\b'"
print(express)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.