Skip to content

Latest commit

 

History

History
32 lines (18 loc) · 2.11 KB

002-Print.md

File metadata and controls

32 lines (18 loc) · 2.11 KB

The print function

The very first thing that is worth learning in Python is the print function. This is something you will be using a lot of in your Python programming journey and it has a very important purpose.

What does it do?

Typing out print, followed by parentheses(), is the function that places your content onto the screen, allowing you to see the results of your code.

Open your text editor

Which text editor are you using? Whatever one you have chosen to use, make sure it is set up to use, display and run Python code. For my examples and in all of the following files I will refer to my own chosen text editor, Visual Studio Code. Ensuring VS Code is set up for optimal Python usage is a job in itself, so please ensure you have followed the instructions for creating your environment first before attempting your first program.

Hello World!

Let's start your first ever Python program by typing

print("Hello World!")

Run your Python code in the terminal or console, or if you're using VS Code, right click and select "Run python file in terminal". This will bring up an inbuilt terminal within VS Code to display the output of your code. Find out how to output Python code on your specific text editor if you're using something different.

What is the print function?

Print allows you to execute visible code in the output field so that you can have a visual of what your code is doing. If you run some valid code that does not have the print function anywhere in it, then the code will still run (as long as there are no errors), however the print function allows you to actually see a visual result of the running of the code. Print is used when a human being is likely to encounter the code and needs to make sense of some of it.

When would I use print?

Use print when you want to see an output from your code, for example what the value of a variable is (values and variables are explained in another chapter), but it is also good for debugging programs, finding faults, and trying to work out how and why a program works or doesn't work.

You will use print a lot! So get lots of practise