好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python怎么把字符串换行输出

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怎么把字符串换行 输出的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于python怎么把字符串换行输出的详细内容...

  阅读:42次