Print function

Imagine yourself jotting a to-do list onto a Post-it Note.

Your writing content directly onto a Post-it.

That's exactly what the print function does, except instead of writing content onto a Post-it, it writes content in the output.

The print function enables you to write content directly in the output.

How to code a print function

Let's write a print function of the to-do list above!

First, let's check out this template for print functions.

print(content)

So, to write the first to-do item onto our webpage, we'll type the following into the content.

print("- Take out the trash")

But, what about the rest of our to-do items?

To include these, all we need to do is write additional print functions.

print("- Take out the trash")
print("- Do the dishes")
print("- Order wig for date party")

Type the code above into your Trinket file. It should look like this now:

Run your file by pressing the "Run" button above your code. You should get the following output on the right of your screen:

What if we wanted to include empty lines?

To include these empty lines in-between each to-do list item, all we need to do is include empty print() functions!

print("- Take out the trash")
print
print("- Do the dishes")
print
print("- Order wig for date party")

Just writing "print" will place an empty line in your output.

Manually type the above highlighted code into your Trinket file. It should look like this now:

Now run your file. You'll see each to-do item is separated by one line like the image below!

Activate AutoScroll

You haven't unlocked all of BUS 104 yet...

Unlock our 42 concept breakdowns & 10 practice problems with guided solution walkthroughs!