python怎么把字符串换行输出-LMLPHP

python中字符串换行输出使用转义字符\n或使用三引号实现:

使用转义字符\n:

print("I'm Bob.\nWhat's your name?")
登录后复制

输出结果:

I'm Bob.
What's your name?
登录后复制

使用三引号:

python三引号允许一个字符串跨多行,字符串中可以包含换行符、制表符以及其他特殊字符。

>>> hi = '''hi there'''
>>> hi   # repr()
'hi\nthere'
>>> print hi  # str()
hi 
there
登录后复制

更多Python相关技术文章,请访问Python教程栏目进行学习!

以上就是python怎么把字符串换行输出的详细内容,更多请关注Work网其它相关文章!

09-05 07:19