Hello World in Python
Summary : Write a simple “Hello World” program and understand a bit about the python environment.
If you already know the basics of installing and running python programs, you can skip this chapter altogether.
“Hello World” Program
print ( "Hello World" )
Go to your python shell and type in
You would see “Hello World” printed on your console – that was easy right ?
Python shell is a simple program that executes python code line by line – like an interactive prompt. How about another print statement ? Like so
Well, you can keep executing as many lines of code as you can – line by line. To execute a full program, python needs it in a file.
print ( "Hello World" ) print ( "Welcome to Python" )
Open a notepad and type in these lines, save it somewhere on your computer.
Now, without going into the shell, you can ask python to execute the contents of the file by typing in
> python hello_world.py
While it is technically not mandatory, it is convention that all python files be given a file extension of .py . You can very well give it any extension you like.
IDLE is an Integrated Development Environment for Python that is bundled as part of the base python installation. It is a simple IDE ( Integrated Development Environment ) that can do basic stuff like file editing, debugging, running programs, syntax highlighting etc.
If you have basic python installed, you should have IDLE installed by default. If you are on Windows, just go to start and search for IDLE under Python folder.
This is how it starts up.
In case you are wondering why my screen is blue and your screen is white, it is just a theme that I have changed. Go to Options -> Configure IDLE
I have selected a dark theme. You can customize it anyway you like.
Click on File -> New File
And start typing up your python code in the file editor.
As you can see, this is much better than notepad. It has syntax highlighting to start with. All your strings are green, functions in purple and so on. Not just that, you can run the python file, right from this window using the F5 keyboard shortcut or click on Run -> Run Module.
And your file is run on the python shell automatically.
You can also use a variety of other features like debugging, code completion, command history and much more. However, it is not even close to a full-fledged Python IDE like the ones we are going to discuss in the next section.