Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update :</strong></p> <p>From <a href="https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep498" rel="noreferrer">Python 3.6</a>, you can use <a href="https://docs.python.org/3/reference/lexical_analysis.html#f-strings" rel="noreferrer">f-strings</a></p> <pre><code>print(f'"{word}"') </code></pre> <p><strong>Original Answer :</strong></p> <p>You can try this (old <a href="https://pyformat.info/" rel="noreferrer">%-formatting</a>)</p> <pre><code>print('"%s"' % word) </code></pre> <p>OR <a href="https://docs.python.org/3.6/library/string.html#format-examples" rel="noreferrer"><code>str.format</code></a></p> <pre><code>print('"{}"'.format(word)) </code></pre> <p>OR escape the quote character with <a href="https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals" rel="noreferrer"><code>\</code></a></p> <pre><code>print("\"%s\"" % word) </code></pre> <p>And, if the double-quotes is not a restriction (i.e. single-quotes would do)</p> <pre><code>from pprint import pprint pprint(word) # Note - This is ONLY for printing, actual string won't have the quotes </code></pre> <p>OR like others have already said (include it in your declaration)</p> <pre><code>word = '"Some word"' print(word) </code></pre> <p>Use whichever <em>you</em> feel to be better or less confusing.</p> <p>And, if you need to do it for multiple words, you might as well create a function</p> <pre><code>def double_quote(word): # return f'"{word}"' # python 3.6 onwards return '"{}"'.format(word) print(double_quote(word), double_quote(word2)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload