1、注释
#使用print输出字符串 print("Hello World!") print("http")#使用print输出字符串 ''' 使用 3 个单引号分别作为注释的开头和结尾 可以一次性注释多行内容 这里面的内容全部是注释内容 ''' #如果三引号是这样的形式就不是注释了 print('''Hello,World!''')
2、Python多个引号
2.1.1 Python中有三种常见的引号:单引号('),双引号(")和三引号('''或""")。通过使用不同类型的引号,我们可以在字符串中插入需要的引号。
下面是一个使用不同类型引号的示例:
string1 = 'I am using "double quotes" inside a string.'
string2 = "I am using 'single quotes' inside a string."
string3 = '''I am using "double quotes" and 'single quotes' inside a string.'''
print(string1)
print(string2)
print(string3)
I am using "double quotes" inside a string.
I am using 'single quotes' inside a string.
I am using "double quotes" and 'single quotes' inside a string.
2.1.2. 转义引号
另一种解决多个引号问题的方法是使用转义字符(\)来转义引号。通过在引号前添加转义字符,Python会将引号作为普通字符而不是字符串的结束符。
下面是一个使用转义引号的示例:
string = "I am using \"double quotes\" inside a string."
2.1.3使用字符串连接
如果我们需要在字符串中插入大量引号,使用上述方法可能会显得冗长而复杂。此时,我们可以使用字符串连接的方法来解决多个引号问题。
下面是一个使用字符串连接的示例:
string = "I am using " + '"' + "double quotes" + '"' + " inside a string."