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?
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?
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'