Python Tricks A Buffet of Awesome Python Features FULL EBOOK PDF 2023.
byDaoued-
0
Python Tricks A Buffet of Awesome Python Features
FULL EBOOK PDF FREE
Introduction to programming in Python language
1. Presentation:
Python is a programming language (like C, C++, fortran, java . . .), developed in 1989. Its main features are:
— “open-source”: its use is free and source files are available and editable;
— simple and very readable;
— with a very extensive basic library;
- large amount of libraries available: for scientific computation, statistics, databases, visualization . . .
— high portability: independent from the operating system (linux, windows, MacOS);
— object oriented;
— dynamic typing: typing (associating with a variable of its type and allocating the memory zone accordingly) is done automatically during the execution of the program, which allows great flexibility and speed of programming, but which is paid for by an overconsumption of memory and a loss of performance;
— provides support for the integration of other languages.
How to make the source code work?
There are two main techniques for translating source code into machine language:
— compilation: a third-party application, called a compiler, transforms the lines of code in an executable file into machine language. Every time you make a change to the program, you have to recompile before you see the result.
— interpretation: an interpreter translates the program line by line into machine language. This type of language offers greater convenience for development, but executions are often slower.
In the case of Python, we can first admit that it is an interpreted language, which uses compiled modules. For expensive algorithmic operations, the Python language can interface with libraries written in low-level languages such as C.
The different versions There are two versions of Python: 2.7 and 3.3. Version 3.3 is not a simple improvement of version 2.2. Please note that not all Python libraries migrated from 2.7 to 3.3.
Let’s detail a little the main characteristics of Python, more precisely, the language and its two current implementations:
• Python is portable, not only on different Unix variants, but also on proprietary OS: Mac OS, BeOS, NeXTStep, MS-DOS, and different Windows variants.
A new compiler, called JPython, is written in Java and generates Java bytecode.
• Python is free, but can be used without restriction in commercial projects.
• Python is suitable for scripts of about ten lines as well as complex projects of several tens of thousands of lines.
• Python’s syntax is very simple and, combined with advanced data types (lists, dictionaries...), leads to programs that are both very compact and very readable. With equal functionality, a Python program (widely commented and presented according to standard canons) is often 3 to 5 times shorter than a C or C++ program (or even Java) equivalent, which generally represents a development time of 5 to 10 times shorter and greatly increased ease of maintenance.
• Python manages its resources (memory, file descriptors...) without the intervention of the programmer, by a reference counting mechanism (similar, but different, to a garbage collector).
• There are no explicit pointers in Python.
• Python is (optionally) multi-threaded.
• Python is object-oriented. It supports multiple inheritance and operator overload. In its object model, and using the terminology of C++, all methods are virtual.
• Python integrates, like Java or recent versions of C++, a system of exceptions, which greatly simplify error management.
• Python is dynamic (the interpreter can evaluate strings representing Python expressions or instructions), orthogonal (a small number of concepts is enough to generate very rich constructs), reflective (it supports meta-programming, for example the ability for an object to add or remove attributes or methods, or even change classes while running) and introspective (a large number of development tools, such as debugger or profiler, are implanted in Python itself).