Print

Print

Creating a variable produces no visible output. To see a value, print it.

city = "Brisbane"
print(city)

Output:

Brisbane

print shows the value of whatever is between the parentheses. Each print produces one line:

print("first")
print("second")

Output:

first
second

print accepts several values separated by commas and shows them on one line with spaces between them:

name = "Parsnip"
age = 36
print(name, age)

Output:

Parsnip 36

Exercise

  1. Create a variable name holding the string "Parsnip".
  2. Create a variable year holding the number 2026.
  3. Print name, then print year on the next line.

Run your code to see the output, then press Submit.

Tests

import unittest


class TestPrint(unittest.TestCase):
    def test_name(self):
        self.assertEqual(name, "Parsnip")

    def test_year(self):
        self.assertEqual(year, 2026)
name = "Parsnip"
year = 2026

print(name)
print(year)
Solution hidden. Give it a real try first.

Sign in to join the discussion.

No comments yet. Be the first to ask a question.

main.py
Console
Press Run to execute your code, or Submit to test and complete this problem.