3 Hello World

It’s something of a tradition when learning a new computer language to start with a program that prints out Hello World. The reason being it’s probably the simplest program that you can write that actually does something.

Well here it is in mpy:


print( 'Hello World' )

It couldn’t be simpler!  Go ahead type it into the  mpyEditor and hit the PROG button. (make sure it is the only line in your program)

Then press the Launchpad RESET button. Look at the console window (the bottom part of the mpyEditor window), you should see

Hello World

 

All output from the Launchpad is printed in green on the console window.

print

The print function is used to print onto the mpyEditor console window.

You can print text or variables with the print command,  and you can use the print command to print multiple values.

Text to be printed must be enclosed in quotes like ‘text’, (or you can use double quotes “text”)

Try


a = 4
print( 'Oh No! There are ', a , 'creepers' )
print( 'sssss BOOM')

Paste this example into your mpyEditor window and press PROG and then the Launchpad RESET button, and this will be printed out

Oh No! there are 4 creepers 
sssss BOOM