Discuss / Python / 疑问

疑问

Topic source

L.W.X.

#1 Created at ... [Delete] [Delete and Lock User]

请问如果要打印
‘hello,

world’

这样写为什么运行不了?

print(r''''hello,

world'''')

LAS

#2 Created at ... [Delete] [Delete and Lock User]

print('hello\nworld') 这样即可

L.W.X.

#3 Created at ... [Delete] [Delete and Lock User]

我是指单引号需要转义,而且需要多行打印的情况下输出:

‘hello,

world’

如果用r''' '''的方式,前后各多加一个单引号的情况下,后面的四个单引号会报错

廖雪峰

#4 Created at ... [Delete] [Delete and Lock User]
print('\'hello,\nworld\'')

烟Mu

#5 Created at ... [Delete] [Delete and Lock User]

print('''\'Hello,

world\'''')

print(r"""'hello,
world'""")

这样就可以了,如果你要print的内容里包含单引号,那么你r后面就跟双引号...反之亦然


  • 1

Reply