Xtralien Scientific Python: Printing To The Console

 

Printing is a simple way for you to display parts of your code.
Commonly, you will use the print function to display the value of variables and how they change as your script runs.
Python provides print among it's standard functions, so it is accessible from anywhere in your code.
If you provide multiple values to the print function, they will be joined together with spaces in between.

As a note, the console is your window through which you can interact with Python whilst it is running. In the Xtralien Scientific Python Distribution this can usually be found in the bottom-right section of the screen.

Printing "Hello World"

To show how simple it is to print to the console in Python, we will print the string "Hello World!" to the console.

print("Hello World!")

This is all that is required to print some text to the console.

Printing Results

When you perform a calculation, or would otherwise like to see how a certain variables change throught the execution of your script, you can print this to the console to check the result.

A simple example of this would be to perform a calculation inside a print function call.

print(1 + 1)

This should print the number 2 to the console. This shows us that this calculation was performed correctly.

You can print variables as well, which is discussed more thoroughly in the next tutorial.

Printing Headers

When you are making a program you will sometimes want to separate what you print. In Xtralien Scientific Python we have included a function to print headers, called print_header that fulfills this need for you.

print_header("A header")

This line will print a header as shown below. The format for the header is centered text with an equal number of hashes on either side to define a clear line.

 

################################### A header ###################################