Reputation: 161
My goal is to print a backslash in Python3. My input is
links22 = ['1',"n","nkf"]
treee = ['<img src={} \\>'.format(i) for i in links22]
print(treee)
The output that I get is:
['<img src=1 \\>', '<img src=n \\>', '<img src=nkf \\>']
The output that I want is:
['<img src=1 \>', '<img src=n \>', '<img src=nkf \>']
And when I try:
print("\\")
The output is:
\
I want to figure out why the first output is \ and in the second is .
Upvotes: 0
Views: 318
Reputation: 194
That is because you are printing an array, not a string. If you print a string then this apply the escape character.
but a example of how do it would be:
...
print(*treee)
# print(*treee, sep=",") # if you want custom separator
Upvotes: 2
Reputation: 393
When you perform print(treee)
, what you are seeing is an escaped representation of the backslash in each of the elements in the list.
If you do this instead:
for a_tree in treee:
print(a_tree)
you will see the single backslash as expected.
Upvotes: 0