Output ====== Output is the information that a program shows to the user. It is how the program communicates results, messages or data back to the person using it. In most beginner programs, output usually means text displayed on the screen, such as a message or a calculated result. Example 1 - Displaying Output in Python --------------------------------------- .. code-block:: python :linenos: print("Greetings!") .. dropdown:: Show Output Greetings! .. admonition:: Explanation This code tells the computer to show the message ``Greetings!`` on the screen. The word ``print`` is a built-in Python function that shows information to the user. The text inside the quotation marks (``" "``) is called a string, which means it is treated as text rather than a number or command. Example 2 - Displaying Multiple Lines of Output ----------------------------------------------- .. code-block:: python :linenos: print("Hello!") print("How are you?") .. dropdown:: Show Output | Hello! | How are you? .. admonition:: Explanation This code uses two ``print()`` functions to display two separate messages on the screen. Example 3 - Combining Variables with Output ------------------------------------------- .. code-block:: python :linenos: firstName = "John" print(f"Greetings, {firstName}! How are you?") .. dropdown:: Show Output Greetings, John! How are you? .. admonition:: Explanation This code creates a variable called ``firstName`` and stores the string ``"John"`` inside it. The letter ``f`` before the quotation marks means this is an f-string, which allows Python to insert the value of a variable directly into the string. When the program runs, Python replaces ``{firstName}`` with the value stored in the variable. Example 4 - Using Multiple Variables in Output ---------------------------------------------- .. code-block:: python :linenos: firstName = "John" lastName = "Doe" print(f"Goodbye, {firstName} {lastName}.") print("We hope to see you again soon!") .. dropdown:: Show Output | Goodbye, John Doe. | We hope to see you again soon! .. admonition:: Explanation This code creates two variables, ``firstName`` and ``lastName``, which store the strings ``"John"`` and ``"Doe"``. The first ``print()`` line uses an f-string, which allows Python to insert variable values directly into the text. When ``{firstName}`` and ``{lastName}`` are used inside the f-string, Python replaces them with the values stored in the variables. The second ``print()`` statement displays another line of text on the screen.