The Print Statement

The Print Statement

Another short simple tutorial about the basics of python covers the print statements. If you’re familiar with other languages, you might already know that a ‘print statement’ is a line or two of code that prints a string ( a combination of letters) or numbers in your local python console. This simple tutorial explains how this simple statement works.

A print statement is useful when you want to find information that your program is computing. The print statement is a built in Python function that starts like this:

When printing in a hardcoded string, unlike other languages, Python is pretty flexible. You’ll get the same result if you use double or single quotes.

Now lets think how to print a variable. When printing a variable, you first define it, and then put it into the parenthesis without any quotes, like this:

Finally, we will learn how to concatenate a variable and a string in a print statement. Concatenating is when you combine two different strings in a print statement like this:

Here we use the plus sign to combine these two strings. The only problem with this is that we can only combine strings. If you try to do something like this:

You would get an error.

I hope that this tutorial helped and please comment with any questions!

Close Bitnami banner
Bitnami