5

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

2 Answers 2

11

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]))
Sign up to request clarification or add additional context in comments.

Comments

0

Another f-string example,

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

gives

"2"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.