Hello World Program in Python

In this example we will display a message hello world.

To understand this program, you must have the knowledge of following topics in python –

  • Basic Syntax of python
  • What are functions in python (Inbuilt functions).
  • What are data types in python.
  • Strings in python
  • Input, Output and import in python.
  • Comments in python.

Program

#This program will print "Hello World" when executed.
print("Hello World")

Output

Hello World

The first line written is just a comment. A comment or a series of comments is avoided by the python interpreter. In simple words, a comment is not a part of your program. It is used just to make the program more readable and understandable. Comments help a non programmer to understand the code, and also in some cases a programmer to understand the code seen after a long time.

In the second line, we have used the print function which is an inbuilt function of python and is used to display output on  the screen. Whatever argument is passed in the function, would be displayed on the output screen. Here we have passed a string “Hello World”. When this program is executed, we will get a message “Hello World” on the output screen.

Things to remember

  • In python, a string should be enclosed inside quotes.
  • There are three ways to write strings in python – Inside single quotes, double quotes or triple quotes depending upon the usage of apostrophes or inner double quotes within the string.
  • Unlike other programming languages, a statement in python does not end with semicolon(;). As you can see there is no semicolon at the end of the print statement. In python, a statement ends as soon as a line break occurs. You only have to press enter when you need to end a statement.

Last Words – The main beauty of python is the short amount of code for a particular functionality as compared to other programming languages.