从零开始学Python

Python习题册013:打印指定文字

2019-01-17  本文已影响0人  iLester

任务011描述

用Python编写一个程序,打印与下文一模一样的文字。
示例文字如下:
a string that you "don't" have to escape
This
is a ....... multi-line
heredoc string --------> example

分析及示例

这个字符串中涉及单引号、双引号,还涉及多行。因此不能单引号或双引号直接来表示——当然可以用置换符来代替其中的特殊字符,例如用\'\n等,但更简单的方式是使用三单引号或三双引号的方式。

示例代码如下:

tempStr='''
a string that you "don't" have to escape
This
is a  ....... multi-line
heredoc string --------> example
'''
print(tempStr)

输出结果:

a string that you "don't" have to escape
This
is a  ....... multi-line
heredoc string --------> example
上一篇 下一篇

猜你喜欢

热点阅读