Python For Coding

Making A Statement

by Neville Dinning Independent Consultant
Neville Dinning Professional   Independent Consultant
No doubt you have seen how just about every programming language or web page building course gets the beginner to print out "Hello World". And I guess that you are wondering just how to do that in Python.

Well here goes!

First get your Interactive console up. It can either be in the Python shell or in the IDLE environment.

At the prompt (usually like this >>>), type in print("Hello World") and then press the enter key.

If all goes well you should see the magic words Hello World printed out on the next line.

So, what's happening here?

The command 'print' is one of the few built in statements in python. That statement expects to receive something that will be enclosed in a pair of brackets to print out. Because "Hello World" is a piece of text, it has to be in quotes for the interpreter to be able to work out what to print. If you want to see what happens when you forget the quotes just try print(Hello World).

Go ahead and experiment with the print statement. Try print(89) or maybe print(5 + 6).

print is reserved keyword in python, and is actually a function that can do a whole lot more than just print to the screen. But that is for later.
The value in the brackets, or argument, is passed to the print statement and if all is correct the interpreter will process the statement and the argument and do just what is asked. (ie: print the result of the argument to the screen in this case).

Any questions? Ask them below as a comment and see what answers you get.
Aug 24th 2016 08:07

Sponsor Ads


Comments

No comment, be the first to comment.
You are not yet a member of this group.