w3resource

Python: Print a specified document

Python Basic: Exercise-13 with Solution

Write a Python program to print the following 'here document'.

Sample string:
a string that you "don't" have to escape
This
is a ....... multi-line
heredoc string --------> example

Sample Solution:-

Python Code:

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

Sample Output:

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

Flowchart:

Flowchart: Print a specified document .

Visualize Python code execution:

The following tool visualize what the computer is doing step-by-step as it executes the said program:

Python Code Editor:

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to print the calendar of a given month and year.
Next: Write a Python program to calculate number of days between two dates.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Unpack variables from iterable:

# One can unpack all iterables (tuples, list etc)
>>> a, b, c = 1, 2, 3
>>> a, b, c
(1, 2, 3)

>>> a, b, c = [1, 2, 3]
>>> a, b, c
(1, 2, 3)