Issue
I would like to print a variable within quotation marks. I want to print out "variable"
I have tried a lot, what worked was:
print('"', variable, '"')
but then I have two spaces in the output:
" variable "
How can I print something within a pair of quotation marks?
Solution
you can use format
:
>>> s='hello'
>>> print '"{}"'.format(s)
"hello"
Learn about format here:Format
In 3x you can use f
:
>>> f'"{s}"'
'"hello"'
Answered By - Hackaholic Answer Checked By - David Goodson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.