📅  最后修改于: 2023-12-03 14:46:31.681000             🧑  作者: Mango
在Python中,我们可以使用单引号或双引号来定义一个字符串。通常情况下,我们需要打印一些字符串内容,这时就需要使用print函数。
下面是打印一个双引号字符串的示例代码:
print("Hello, world!")
输出:
Hello, world!
需要注意的是,如果你要在字符串中使用双引号,可以在字符串前加上转义符\
,也可以使用单引号定义字符串。
示例代码:
print("I'm using \"double quotes\" in this string.")
print('I\'m using "double quotes" in this string.')
输出:
I'm using "double quotes" in this string.
I'm using "double quotes" in this string.
此外,我们还可以使用三个双引号或单引号来定义一个多行字符串,并使用print函数打印出来。
示例代码:
multi_line = """This is a multi-line
string that allows us to include many lines of content.
We can use regular quotes "like this" or we can use single quotes 'like this'.
It's really up to us."""
print(multi_line)
输出:
This is a multi-line
string that allows us to include many lines of content.
We can use regular quotes "like this" or we can use single quotes 'like this'.
It's really up to us.
总之,在Python中使用双引号打印字符串非常方便,非常容易理解。