Hello world!
July 1, 2010 15 Comments
(Works for both Python 2.7 and Python 3)
Your first program, for reasons lost to the mists of time, must always be a “hello world!” If you don’t do it, something bad will happen to you (or one of your friends, relatives, distant relatives, acquaintances or some other citizen of your country). Believe me, it is scary.
So, to avoid such a horrible fate, repeat after me:
>>> print('hello world!') hello world! >>>
Phew! We’re done. You should notice that the print statement here did something – it printed the letters between the ” (inverted commas) and it printed them on the next line. Try it for yourself, but remember to press the enter key at the end otherwise nothing will happen.
Congratulations, you’re now a programmer (in training).
Excellent idea for a blog! Python is a fun language and a great place to start learning how to write software. Looking forward to future posts 🙂
Oh dear, with the new python 3.2 this results in a SyntaxError…
Now it should read:
>>> print(‘hello world’)
hello world
thanks! i was like oh what i do bad :c
@MeneM:
These tutorials are based on Python 2.6/2.7. Substantial changes happened to the language with version 3. Print, in particular, won’t work but other stuff might not as well. If you want to follow the tutorials, you should get a copy of the 2.7 branch. See: https://python4kids.wordpress.com/getting-started/.
Ah ok, makes sense, but isn’t 2.6/2.7 older now? Surpassed by the updates?
Over the next few years people will transition from the 2.7 branch to the 3 branch. For the time being 2.7 is the go (eg more third party modules for 2.7 than for 3, other people are more likely to have Python 2 than Python 3 etc). Sometime or other that will change. Until then…
For a discussion of the issue:
http://wiki.python.org/moin/Python2orPython3
For a short summary of differences see:
http://docs.python.org/release/3.0.1/whatsnew/3.0.html
Here is a cheatsheet someone put together:
http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/promotions/python/python2python3.pdf.
That’s the most hilarious Hello World example I have ever come across!
Pingback: python4kids 一個老爸教8歲的兒子寫python所用的blog » Kevinwatt's Blog
Squee! This was my very first program, and I stayed up ’till bedtime going through the first 4 tutorials. I’m going to have Python down pat by the end of the summer holidays! 🙂
Good luck Alex. Let us know how you get on.
Pingback: Python (Computer Coding) | The Chronicles of Nerdium
Pingback: 3: Hello World! | Python Tutorials for Kids 13+
Beautiful articles, I’m shopping on Facebook!
Thanks!
Pingback: click for more