Hello World is the first program written by developers to learn programming language.

It is easy and quick to code a language in Python.

This post covers

  • Writing a simple hello world program in Python
  • Print the string to the console
  • Compile and execute a program using the command line.

How to write a Hello World program in Python?

Python program contains code statements created in a text file and saved with the extension py.

  • Open any editor
  • Create a file called HelloWorld.py, where py is an extension for Python code statements code.
  • Add the below code
Hello world sample program
Basic program to print hello world to console
First code to write in Ruby language
 print("Hello world Welcome to Python programming\n")

The above Python contains two types of lines - comments and print statements

  • Comments are single-line or block/multi-line comments.

Single lines are started with #, followed by single-line text in a single line Multi-line comments span in multiple lines, starting with """ and ending with """ .

The print function prints the string enclosed in double quotes to standard output.

Unlike other programming languages, There is no main function in Python

How to compile and execute the Python program

To execute and run a Python code, a Python compiler is used to compile and execute a program.

The compiler compiles program code to bytecode or native code and

  • Python tool compiles the Python to native code and executes the code

The python tool compiles the Python code into native code.

python HelloWorld.py

It generates and prints the string

 Hello world Welcome to Python programming.