INTRODUCTION

Before addressing the topic “The Python language introduction” let’s make a brief description of what the language is. Python is a multi-paradigm language that has among its main objectives: dynamism, simplicity and flexibility. It supports the object oriented paradigm, structured programming, and many functional and reflection programming features. The most immediately recognizable features of Python are the untyped variables and the use of indentation for specification syntax, in place of the more common parentheses. Other distinctive features are the overloading of operators and functions through delegates, the presence of a rich assortment of basic types and functions and standard libraries, advanced syntaxes such as slicing and list comprehension. Type checking is strong (strong typing) and is done at runtime (dynamic typing).

VARIABLES AND OTHER CHARACTERISTICS

A variable is a container that is associated with a label (the name) that can be associated with different containers even of different types during its life time. A garbage collector system for automatic freeing and recovery of working memory is part of Python. Python bears some resemblance to Perl, but its designers have chosen a more basic and uniform syntax with the aim of improving the readability of the code. Similarly to Perl it is often classified as a scripting language, but while it is useful for writing system scripts, as an alternative for example to bash, the large amount of libraries available and the ease with which the language allows you to write modular software also favors development of very complex applications.

WE INSTALL PYTHON

Go with your browser to www.python.org, select the Download tab and download the version of Python for your OS. The version that opens depends on your Operating System, I am using Windows 10 and the current version of Python is 3.9.7 Once installed the program configures the system environment variable Path by setting the path of the Python installation directory. Restart your computer and everything should be ok. Open a Python schell to see if the current version is the one you have installed.

Python installation

CHOOSE THE EDITOR

For this course, the editor I decided to use is Visual studio code, however there are several such as atom, this editor is also multi-platform and you can download it at https://atom.io/

Atom

CONFIGURE VISUAL STUDIO CODE

At the moment I recommend you to install the Visual Studio Code extensions highlighted in green to write Python code.

Visual studio code environment

WE WRITE THE FIRST PROGRAM IN PYTHON

Python is a runtime environment that can be run in two different ways, the first is the interactive schell typing the python3 or python command in the windows schell activates the first mode that we have said to be the interactive schell.

Interactive shell

The schell is very useful as it allows you to write Python instructions that are executed immediately. In some cases this is very useful such as for example to learn the language or to test code snippets before writing the actual program. The other runtime mode is to directly execute scripts that in Python have the extension .py in this case the command shown in the figure is written on the schell.

Script execution

Now let’s write a very small program that checks if the number entered from the terminal is odd or even. We define a Python function which is nothing more than a series of instructions that we then call as many times as we want. It is good to immediately clarify that Python, unlike C#, does not use curly brackets to delimit blocks of code, in Python the code must simply be indented.

THE PYTHON FUNCTION

This function first acquires a number from the terminal, transforms the string into an integer, then uses the modulo % operator to see if the number entered has a remainder or not. Finally, with a conditional test we verify that if the remainder is zero it is displayed in the terminal with the print statement that the number is even, otherwise odd. A function is declared with the statement def followed by the name of the function and closed with(): to indicate to Phyton that the function does not accept parameters. The colon indicates that the declaration is complete. Then you go to the head and indent the code by 4 spaces to the right with the Tab key.

First Program

WRITE THE SAME PROGRAM IN VISUAL STUDIO CODE

Visual Studio Code First Program
def paridispari():
    inp = input("Inserisci un Numero ")
    numero = int(inp)
    modulo = numero % 2
    if modulo == 0:
        print("Numero Pari")
    else:
        print("Numero Dispari")
#Per eseguire il programma digitare nel terminale
#python o python3 (guardare la directory di installazione di Python
#per sapere quale comando utilizzare)
#seguito da uno spazio e dal nome del programma .py.
#In questo caso python Program.py
paridispari()      

LINK TO GITHUB CODE

GITHUB

THE PYTHON LANGUAGE INTRODUCTION-LINK TO C SHARP

THE C# LANGUAGE