First Python program and indentation

Let's start our first program of Python.

Example of Python Program by printing "hello_world"

ubuntu@ip-172-31-44-226:~$ cat python_first.sh

print ("hello_world")

ubuntu@ip-172-31-44-226:~$ python3 python_first.sh

hello world

Unlike in shell, we use echo to display the output

In python we print the value using print syntax like the above image.

print " your message " and execute the Python program.

You can use the command python3 filename.py file extension must be in .py format.

Indentation in Python

The most important topic to understand is an indentation to write any Python program.

  • Whitespace is used for indentation in Python, Python indentation is mandatory.

Role of Indentation in Python

  • Like other programming languages such as Java use {} brackets to define a block for indentation. Python use of indentation to highlight the blocks of code.

Let's see examples where indentation is applied .

Highlighted with the blue line are indentations and whitespace are called indentation.

The above program has been executed successfully with indentation is maintained throughout the program.

Let's see an example and error in case indentation is missed.

Program error out with indentation error.