Python Hello World Program

In the previous tutorial, we have looked over the Introduction to Python Programming. Now lets jump to actual programming. In this tutorial we will write our first Python program.

To start Python in Windows Environment Click Start > Python > Python IDLE

As soon as you start Python IDLE, you get a Python Shell which lets you use an Interactive Mode in Python Programming Environment.

 

Python Hello World Program

 

Press Enter after typing this statement. You will get the output as shown below.

Output

Python Hello World Program

 

Note: Before Python 3, print statement was used. After Python 3 version print statement is modified to print() function. Still if you use print statement in newer version then you will not get an error. One more thing to note here is, semicolon (;) is optional in Python. If you don’t add semicolon at the end of a statement then you will not get an error.

 

Python is very clear and concise. It has excellent easy to use interface and a very easy learning environment.

Python in Windows provides us with a Graphical User Interface Integrated into the IDLE. Python IDLE provides us with two modes of environment:

1. Script Mode Environment
2. Interactive Mode Environment

Interactive Mode comes in by default that lets you use the Python programming environment in Python Shell. There, you can directly write commands and execute it to see the output. It is best for evaluation purposes. Interactive Mode is probably the quickest way to try out a small idea and check its results.

As told in the previous tutorial, Python is a scripting language rather than just a programming language. The Interactive Mode is perfect if you plan to save programs and run them later. To start the Script Mode in Python IDLE, select File at the top left corner of Python Shell and click on New File.

You can think of Python Interactive Mode as a scratchpad wherein you can try new ideas quickly so as to verify its usage whereas Python’s Script Mode is where you can craft the final product.

Here, you can write your programs in a file and save it to create an executable file.

Python Code is case-sensitive. So, print, Print and PRINT are different. Python doesn’t accept Print or print statements. It generally accepts only lowercase characters. It has been found that Python code length is around 40% of what other languages such as C, Java, C++ and others consume.

 

Python Hello World Program Modified

 

Note: If you’re using Python 2.7, you may have to use raw_input instead of input.

Explanation

1. The first line of this program is a Comment. The Python interpreter completely ignores these comment lines and is totally for the programmer. Comments are invaluable feature for any programmer. It lets us to understand the program in a better way as it can be easily interpreted by humans in any language so as to understand the code in a better way.

Syntax

 

2. The Second line is the print command which lets us to display a statement over the console screen for the End User of the program. This command tells the computer to display text on the screen. You can use either quotation marks (double) or apostrophes in the print command.

Syntax

OR

 

An Expression can be a statement like Hello World or something like 2+5 which is evaluate to 7 on hitting Enter.

3. The Third statement is probably more useful in Script Mode Environment in Python. This statement helps the output screen to wait for the user to press Enter and then Exit the program otherwise it will just execute within seconds and the program terminates. You can relate it to getch() function in C Programming Environment.

Syntax

 

This was all about our Python hello world program. If you have any doubts regarding above tutorial then feel free to ask it by commenting below.

1 thought on “Python Hello World Program”

  1. As you have mentioned that, you wuilll not get an error if you wouldn’t use semicolon, but i am getting an error. please clarify it.

Leave a Comment

Your email address will not be published. Required fields are marked *