Python Tutorial - Hello World

Jinku Hu Dec 21, 2022
Python Tutorial - 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

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:

Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn Facebook