字符串转换

时间:2009-12-09 12:44:19

标签: python string

s ='这是样本'

我需要像这样转换

s='"This is sample"'

输出= "This is sample"

如何在动态中做到这一点 提前致谢

2 个答案:

答案 0 :(得分:5)

orig = 'This is sample'
converted = '"%s"' % orig

答案 1 :(得分:1)

>>> s= 'This is a sample'
>>> s = '"' + s + '"'  # or s = '"%s"' % s
>>> s
'"This is a sample"'
>>> print(s)
"This is a sample"
>>>