01.08.2023

First Python Program

Introduction

The simplest Python program is to print a string saying Hello, World! Let's figure out how to write it. To do this, we need to install the latest version of Python on our system..

Preparing before starting

To get started, you need to expand virtual environment  in Python 3. You will also need to initial setup our server.

First program

Let's use the Python 3 command line:

python3

Let's execute the command that displays information:

print("Hello, World!")

At the output we get the result:

Hello, World!

The print() statement performs the function of outputting data to the console.

Let's create a file with Vim:

vim TestFirstProgramm.py

And add a one-line code:

print("Hello, World!")

To run the program itself, run the command:

python3 TestFirstProgramm.py

Consider also the use of variables in code and the use of print() to print information from variables:

#Assigning values ​​to variables
a = "Hello,"
b = " World!"

print(a+b)

At the output we get the result:

Hello, World!

Variables are assigned not only string data types, but also integer or floating point numbers.

In the following example, consider the multiplication of numbers using variables. Let's assign the value 5.60 to the variable "a" and the value 5 to the variable "b" and multiply them using the print(a*b) statement, according to the following code:

python3
a = 5.60
b = 5

print(a*b)

We get the following result:

#Result:
28.0

Conclusions

As a result, we can say that writing the first program in the Python programming language is not difficult. There are various possibilities such as: