在Python中,要打印带有双引号的字符串,你可以使用 `print` 函数和字符串格式化。以下是几种常见的方法:
1. 使用 `%` 格式化字符串:
str1 = "Hello world"
print("\"%s\"" % str1)
2. 使用 `format` 方法:
str1 = "Hello world"
print('"%s"' % str1)
print("{}{}".format(str1, str1))
3. 使用 f-string(Python 3.6+):
str1 = "Hello world"
print(f'"{str1}"')
4. 使用 `json.dumps` 方法(如果你需要将列表中的每个元素都用双引号包围):
import json
lst = ['SA41', 'SA42', 'SA43', 'SA44', 'SA45', 'SA46', 'SA47']
print(json.dumps(lst))
以上方法都可以用来打印带有双引号的字符串。选择哪一种方法取决于你的具体需求和Python的版本