СHRISTMAS
WHEEL OF FORTUNE

Tap the button and win a guaranteed prize right now!

By registering, you are signing up to receiving e-mails.
DF
February 27 2023
Updated August 1 2023

First Python Program

Linux Ubuntu

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:

    • writing a module for projects;
    • creating classes inside modules;
    • defining a function within a class;
    • importing modules using the import statement.
Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.