1

I have the following program:

x = 0

while x <= 10:
   print(x, '\10')
   x = x + 1

It then prints:

0 @
1 @
2 @
3 @
4 @
5 @
6 @
7 @
8 @
9 @

Instead of:

1 \ 10, 2 \ 10 And so on...

Why is the program doing this?

Rlz
  • 1,649
  • 2
  • 13
  • 36

1 Answers1

3

You're escaping the 10 with a \ symbol and python is interpreting \10 as a code for the @ symbol instead. You can fix this by either placing an r character as a prefix for the string or by escaping the backslash with another one.

Fix:
    r'\10' #Raw string
Or:
    '\\10'
GarethPW
  • 399
  • 1
  • 3
  • 11