Python Hello World

We will start with the basic Python “Hello World” program.

>>> print("Hello World!")
Hello World!

That’s it! You can see the simplicity of Python by its syntax; no header files are included as in C\C++, no need to define any main function and so on. You also don’t need statement terminators, and you just write print and the content Hello World enclosed in double quotation marks inside parenthesis.

Python Basic syntax:

Consider the code below which multiplies two numbers:

# Multiplying two numbers
x = 4
y = 2
result = x * y
print(result)
8

Explanation of above program:

  1. The first line is a comment starting with #. Comments are the lines that are not executed but ignored. So they do not disturb the normal flow of a program.
  2. The next line x = 4 is the definition of a variable. The name of the variable is x which stores 4.
  3. Similarly, you can see y = 2. y is a variable which stores 2.
  4. The line result = x * y is a Python statement which evaluates the multiplication expression x*y and stores the result in the variable result. To multiple two number * operator is used.
  5. print() statement is used to print strings or values of variables on the screen.

You can note here there are no curly braces (delimiters); in Python to represent any block indentation is used. For example if you are creating a class, you need to use indentation as follows:

class1:
    class2:
        statements
    class2:
        statements