Tag Archives: python tutorial

Python online help

To consult the Python online help we need to type the help () command to receive information on the use of the python interpreter. After issuing the command, you receive a welcome message from the online help function that invites us in case we were beginners to see the tutorial available on the Internet at the following url:


>>> help()

Welcome to Python 3.6's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.6/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules. To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics". Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

In the online help, as already mentioned with the help () command, just enter the name of any module, keyword or topic to get help in drafting Python programs. To exit the online guide to return to the interpreter, simply type “quit”. Instead, to obtain a list of available modules, expected keywords or usable topics, you will need to type “modules”, “keywords”, or “topics”.

Each module then has a summary contained in the online help in which all its features are listed, while to list the modules whose synthesis contains a given word we will have to add it to the word modules. For example, to get information on the array module we will insert this name in the shell of the online help to get the information shown in the figure.

Python online help

It is therefore advisable to consult the online help of the Python interpreter whenever you find yourself having to use a Python resource that you do not know adequately; we have seen that through the help of the Python Interactive Shell it will be easy and immediate to obtain sufficient documentation.



Python Interactive Shell

To start Python or more correctly to open the Python Interactive Shell just click on the Start menu to find the shell icon ready in the frequently used programs, or just click on All Programs then on the entry Active State Active Python 3.1.

After activating the Python Interactive Shell, we will find a window where you can type our python instructions from the command line. Let’s start with the classic message that programmers use to send to the shell to test its regular operation; I refer to the most classic of messages: “Hello World”.

To display a message from the shell it will be necessary to print it, and then what could be the command that allows us to do this if not print (which translates into Italian means printing), this confirming the fact that reading the Python code is equivalent to reading a common listing in English.

Then to display the message “Hello World” at the command prompt, just type the following statement:

print ('Hello World')

to obtain the printout of the message as shown in the figure.

python prompt

Having done this, let’s see now how to receive a first and immediate help from the Python interactive shell; in fact, when the shell opens, the following message is displayed:

Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.



Python prompt

In order to be immediately operative, we start to see the simplest of the programs we can write: that is, a simple sequence of commands.

The Python prompt will be of the type:

Python 3.3.2 (v3.3.2: d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AM
D64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

So let’s start working with the Python prompt, writing the individual commands directly, then print the programmer’s greeting on the screen:

>>> print (‘Hello world!’)
Hello World

How you can verify the print command does nothing but ask Python to show us on the video the string contained in the brackets. In our case it will write the sequence of characters ‘Hello world’.

python prompt

This sequence of characters is defined in the jargon of the character string programmers or simply string.

Python software

Let’s first see where to find the Python software to install on our machine in order to start programming with Python. The packages that we will have to install are available on the official website of the language at the following url:


Naturally, before downloading the software versions, we will have to inform ourselves about the type of machine at our disposal and the operating system installed on it. However, remember that Python is available for practically all operating systems in circulation.

The Python interpreter will allow the translation of our Python code into a language that our computer can understand and that will allow it to execute the instructions contained in it. In the writing period of this book, the current version of the Python interpretation is 3.1.2 which represents the stable one and that is why in the examples that will accompany us in the following chapters we will refer to that version.

We can safely download the Python software from the network, as the programming with Python is all open source and therefore freely downloadable from the internet where we can find sites that in addition to providing detailed procedures for downloading the current version of the software also provide satisfactory documentation.


Python portability

One feature that determined Python’s success in the global programming landscape was its extreme portability; there are versions of Python for Linux platform (its natural environment since it was developed here), for Unix-like operating systems, Mac OS, and Windows in all its versions.

The versatility of Python manifests itself in its entirety when there is a Python version also for the obsolete operating system with an MS-DOS-oriented interface.

Python portability

But the development of Python does not stop at the platforms just seen but extends to those that are widely used today for the programming of mobile phones, satellite navigators and so on. Last but not least, Python can be used on Java and in .NET virtual machines.

Python syntax

Python’s syntax makes it perfect for building simple DSLs for use within your application, thanks to its syntax and metaprogramming features.

We have already specified that Python is totally Object Oriented, this translates into the fact that in Python everything is an object. In this aspect it manages to outclass the language to objects par excellence and that is Java since in Python there is no distinction between basic types and objects, at the same time the object-oriented programming in Python is neither invasive nor annoying, and this is due to its greater purity.

A feature particularly appreciated by Python programmers was the possibility of using so-called blocks that represent an uncommon feature in the most widespread languages and which allow to represent different problems, even very different from each other, with clear and meaningful methods.

The Python is loved, in the same way, by professional programmers who appreciate the most advanced features, and beginners as it is particularly suitable to be learned as a first language.

In fact, thanks to its simplicity, it is possible to learn the basic notions of programming, without having to worry about innumerable conventions and aspects not strictly related to the realization of numerical algorithms.

Moreover Python is effectively expressive in that it provides many built-in data structures and types (the built-in types represent the types already defined in the language); examples are:

  • dict,
  • lists,
  • regexp,
  • whole numbers of arbitrary size.

The Python syntax means that the classes have a very detailed interface, which determines a simplicity in use in common operations.

Python features

The characteristics of Python make it a programming language above all simple, its use is learned in a few days, without presenting great difficulties thanks to a streamlined and very practical syntax; in addition, by presenting a really large number of bookcases included in the distribution and integrated with the installable ones, it is possible, as already anticipated, to realize our programs in a very short time.

Python is particularly dynamic, an example is provided by the fact that the variables can be safely used without the need to declare the type, then the interpreter will be able to identify them; all this, however, without losing precision because operations that are not allowed between different types will cause an error, ie it will never happen, in a more or less hidden way, that a value of a certain type is used as if it were of a different type (strong typing).

Thanks to this, an operation of type 1+ “2” (sum of a number and a string) will cause a runtime error, unlike languages ‚Äč‚Äčlike php or perl that do not allow a similar control.

In Python it is possible to manipulate classes and methods at runtime, ie they can be added, deleted or modified. In this way many of the things that in other languages represent complex structures can in Python constitute simple methods; it is also possible to add custom classes and methods, creating Domain Specific Language (DSL). A Domain Specific Language is a mini-language suitable for a specific problem, the ideal would be to have a language for every purpose, but without the problem of having to learn it from scratch each time.