Steven Jones
Steven Jones

Reputation: 99

Remove space from print output - Python 3

I have this..

the_tuple = (1,2,3,4,5)
print ('\"',the_tuple[1],'\"')

showing

" 2 "

How can I get the output to show "2"?

Upvotes: 5

Views: 4964

Answers (2)

Subham
Subham

Reputation: 411

Another f-string example,

the_tuple = (1,2,3,4,5)
print(f'"{the_tuple[1]}"')

gives

"2"

Upvotes: 0

Jon Clements
Jon Clements

Reputation: 142126

Use:

print ('\"',the_tuple[1],'\"', sep='')
                               ^^^^^^

Note that those escapes are completely unnecessary:

print ('"', the_tuple[1], '"', sep='')

Or even better, use string formatting:

print ('"{}"'.format(the_tuple[1]))

Upvotes: 11

Related Questions