The print function

The quickest way to see the contents of a variable is to use the print function. You’ve seen this in some of the examples in the last chapter.

What is a function?

A function is a block of code that could be a couple of lines long or thousands. All you know is that you want to use this code in multiple places in your program. So you don’t want to have to type all of it out each time you want to use it.

Just like variables you want to have to change as few places as possible. Not only does this reduce the risk of a typo but saves you a lot of work.

You can spot a function by the brackets.

print("Hello world")
print(total)

Within the brackets are the values that you are passing into the function. With the print function you can pass in multiple values and if you do they will be joined together with spaces.

print("Hello", "World")

But for this course I want you to show that you understand concatenation. So make sure you glue those strings together and only send one variable to the print function.

string_start = "Hello"
string_end = "World"
complete_string = string_start + " " + string_end
print(complete_string)

The print function can accept all the data types that we covered before. But if you do want to concatenate them with a string you will need to convert them to a string using the str() function.

total = 105
print("Total: " + str(total))

We will cover functions in more depth later on in the course.

Report a Glow concern
Cookie policy  Privacy policy

Glow Blogs uses cookies to enhance your experience on our service. By using this service or closing this message you consent to our use of those cookies. Please read our Cookie Policy.