fbpx
python-print-function-output-large-help

Python Print Function

Python Print Function

Every programming language has a command that will output text on a computer screen.  In Python, it’s called the print function.  Most electronic devices communicate in some way with the user. Usually, they display some sort of text. Regardless of the coding language, mastering text (also called a string) output is usually the first step in learning to code.

Printing as a Function?

When you think about it, you’re “printing” onto a screen.

python-print-function-code-output-example1

This image demonstrates the output of 2 print functions: the first line outputs the words “Hello world!” and the second line does the arithmetic and outputs the result of 12.

Python’s print function has a fair amount of syntax, just like Java and C. Brackets are needed around anything you want Python to output.

Let’s look at another example:

python-print-function-code-output-example2

These lines would output the math statement on one line and the result on the next. That’s okay, but we’re not used to seeing it that way.

So, a coder’s next task is to learn how to manipulate the output to make it more user-friendly. And, of course, Python’s print function can do that when you learn more syntax!

Python Print Function Syntax

Syntax has the same meaning in coding as it does in English. In coding, syntax defines the rules for a specific function. If a programmer doesn’t follow the rules, errors will occur.

python-print-function-output-example3

That’s more like it! All it took was learning some new syntax to put the two statements together:

The comma between the string “10 + 2 = ” and math statement 10 + 2 tells Python you want to join two elements using the same print function. Now they are both on the same line, and it looks right.

So, how does print work?

The most important part of coding is understanding how and why things work the way they do. Kids need to be asked the right questions to help them understand how a function works.

python-print-function-questions

Learning a bit more about Python’s print function can make a big difference!

Syntax Errors?

Python’s print function is pretty straight forward, and although it does have a lot of syntax at the advanced level it can still be taught to kids. Kids will always learn something new when they’re ready for it.

python-print-function-error-questions

It’s pretty easy to make a syntax error until you figure out the rules. But, it’s also the best way to learn how to code.

Python won’t run the program if it encounters a syntax error. It’s just like using a spell-checker to correct your English.

Designing Output

Coders can create interesting designs with Python’s print function.

It’s always a good idea to plan your program on paper first. Grid paper is an excellent tool to have kids work out their designs.

If you’re interested in teaching Python I do have a resource to start you off. It includes answer keys as well as lessons with teacher notes. Click here.

You can also buy the full unit (which includes a test) here.


Graphics with Python

Maybe you’re more artistic? Check out Python Turtle’s Basic Graphics Functions.

More Resources