How do I include quotation marks in a print statement if I am using a variable

时间:2015-05-12 22:15:15

标签: python variables printing

driver.find_element_by_css_selector("li.last level1>a>span")

If word is word = input("Enter a word: ") word_length = len(word) print("The length of", word,"is ", word_length) , the output will be:

'back'

I want the output to be:

The length of back is 4

2 个答案:

答案 0 :(得分:5)

The Good way:

The best way is to use format

new_list.append({'Mw': Mw_Price[0], 'Price': Mw_Price[1]})

The Bad way:

Using C-like statement, note that this is de-emphasised, (but not officially deprecated yet)

print("The length of '{}' is {}".format(word, word_length))

The Ugly way:

One way is to have your string add with a print("The length of '%s' is %s" % (word, word_length)) and using sep attribute

'

答案 1 :(得分:0)

You can use <!doctype html> <html prefix="og: http://ogp.me/ns#"> <head> <title>HTML5 site</title> <meta property="og:title" content="The Rock" /> </head> <body> </body> </html> of a word to include the Python quotation marks (as they appear in e.g. the interactive interpreter); this has the added benefit of working reasonably when quotes are already in the string:

repr