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 console
  • Compile and execute a program using the command line.

How to write a Hello World program in Python?

Python program contains a code statements created in a text file and saved with 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 print 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,python compiler used 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 execute the code

The python tool compiles the python code into native code.

python HelloWorld.py

It generates the and print the string

 Hello world Welcome to Python programming