如何在引号内打印变量? [英] How to print variable inside quotation marks?
本文介绍了如何在引号内打印变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在引号中打印一个变量.我想打印出"variable"
I would like to print a variable within quotation marks. I want to print out "variable"
我已经尝试了很多,有效的是:
'"', variable", '"'
–但是我在输出中有两个空格-> " variable "
I have tried a lot, what worked was:
'"', variable", '"'
– but then I have two spaces in the output -> " variable "
在没有逗号的情况下执行print '"'variable'"'
时,会出现语法错误.
When I do print '"'variable'"'
without the comma I get a syntax error.
如何在一对引号内打印内容?
How can I print something within a pair of quotation marks?
推荐答案
您可以使用format
:
>>> s='hello'
>>> print '"{}"'.format(s)
"hello"
在此处了解格式:格式
这篇关于如何在引号内打印变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文