# Python

## Summary


Python is a general purpose programming language that blends procedural, functional and object-oriented functionality in scripting mode. It has efficient high-level data structures, powerful flexible string handling and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. This pseudo-code nature of Python is one of its greatest strengths. It allows you to concentrate on the solution to the problem rather than the language itself. Python has an extraordinarily simple syntax. It's creator, Guido van Rossum, says, 

> Python is an experiment in how much freedom programmers need. Too much freedom and nobody can read another's code; too little and expressiveness is endangered.

## Discussion

### What's so attractive about Python?

    + Python can be easy to pick up whether you're a first time programmer or you're experienced with other languages.
    + Python allows you to write the programs in fewer lines of code.
    + Very clear readable syntax and keywords, with proper indentation a part of syntax checking.
    + Declaration of variables is not required. Object-oriented and imperative programming can be mixed.
    + Easy to manipulate large data, can perform linear algebra and matrix operations with `pandas`, `numpy`, `scipy`, `scikit-learn`, etc. for machine learning.
    + Lists, stacks, queues, dictionaries—you name it, Python has it. Moreover, complex data structures like graphs can be easily implemented in python using a list of dictionaries.

### How do you classify Python as a language?

Python is a programming language that lets you work more quickly and integrate your systems more effectively. It's a high-level, interpreted, interactive and object-oriented scripting language. It incorporates modules, exceptions, dynamic typing, very high-level dynamic data types, and classes.

    + **Python is Interpreted**: Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to Perl and PHP.
    + **Python is Interactive**: You can access a Python prompt and interact with the interpreter directly to write your programs.
    + **Python is Object-Oriented**: Python supports object-oriented style or technique of programming that encapsulates code within objects.
    + **Python is a Beginner's Language**: Python is a great language for the beginner-level programmers and supports the development of a wide range of applications from simple text processing to WWW browsers to games.
    + **Python is Portable**: It runs on many Unix variants, on macOS, and on Windows 2000 and later.

### What are some applications where Python is suited?

Python is versatile and it's been used in a variety of applications: console programs, GUI apps including games, server-side programming for web/mobile apps including creation or use of web frameworks, apps that handle media (image/audio/video), enterprise apps for ERP or CRM, data-oriented apps that can handle data in various formats and file types, database-driven apps, networking, scientific apps that require complex and intensive numerical computations, software development tools such as build tools, test automation, software delivery tools such as package managers or installers, system administration utilities, etc. 


### I've heard of The Zen of Python. What's that?

Back in August 2004, Tim Peters released an informational document that stated best practices or guiding principles that can benefit Python developers. This document was released as PEP20 -- The Zen of Python. Developers who wish to understand them can do so by studying sample Python code.


### As a developer, how do I get started with Python?

Python can be installed on Windows, Linux or Mac. The default Python distribution by the Python Software Foundation can be installed. For scientific applications, the Anaconda distribution is recommended.

Among the IDEs are IDLE, PyDev for Eclipse, PyCharm, Sublime Text, Visual Studio Code, Spyder, etc. Sublime Text and Visual Studio Code are generic editors that can be enhanced with plugins to support Python. For scientific apps, Spyder may be a good IDE to use.

Python comes with an interactive shell but IPython is an enhanced shell that offers more features. Jupyter Notebook allows programmers to combine code, results and descriptions into a nice flow that can be shared with others. IPython and Jupyter Notebook are part of Anaconda distribution.

For installing new packages or updating existing ones, `pip` is the tool to use. Since developers often work on multiple projects, and each project may use different packages or even versions of Python, it's recommended to use *virtual environments*. A virtual environment can be created using `pip install virtualenv`.

PEP8 is a style guide developers should read to make their code more readable and maintainable. 


### Can Python be used in embedded systems?

Yes. Devices that could be considered as embedded by modern standards and can run tuned versions of CPython include: 

    + Gumstix
    + Raspberry Pi: The "Pi" in Raspberry Pi comes from Python.
    + BeagleBone Black*MicroPython* is a lean and efficient implementation of a subset Python 3. It's optimised to run on microcontrollers with as little as 256K of Flash and 16K of RAM. The *pyboard* is a compact and powerful development board that runs MicroPython. A quick reference to programming the pyboard is available. MicroPython is supported on a number of MCUs, including many variants from STMicroelectronics. 


### Can I use Python along with other languages in a single program?

Yes. For example, time-critical code could be in C and this could be invoked from within Python.

In fact, Python is a specification that has been implemented in many different languages. This makes it easier to interface Python with code from other languages. The interpreter compiles Python source code into bytecode and execute on a virtual machine. Following are some existing implementations: 


| Implementation | Virtual Machine | Compatible Language |
| --- | --- | --- |
| CPython | CPython VM | C |
| Jython | Java Virtual Machine | Java |
| IronPython | CLR | C# |
| Brython | JavaScript engine (eg. V8) | JavaScript |
| RubyPython | Ruby VM | Ruby |

Python implementation in RPython (a subset of Python) is called *PyPy*, which is fast due to JIT (just-in-time) compilation. PyPy aims to be cross-platform, memory-light and stackless-supportive. 

## Milestones

Dec  
1989

Guido van Rossum at CWI in the Netherlands encounters some shortcomings with ABC programming language on the Amoeba operating system. He likes the scripting syntax of ABC but doesn't want to create an Amoeba-specific language. So he decides to create an extensible language giving due importance to exception handling. He starts the implementation during 1989 Christmas holidays. 

Feb  
1991

Guido van Rossum uploads Python to USENET, thus making it publicly available for the first time. 

Oct  
2000

Python 2.0 is released. Starting from this release, the development of the language becomes more open and community driven. 

Oct  
2008

Python 2.6 is released. The development of this release is synchronized with that of Python 3.0. Thus, Python 2.6 incorporates some changes that are part of Python 3.0. This backporting is expected to make way for easier migration of Python 2.6+ code to Python 3.x. Module `future_builtins` has 3.0 semantics. 

Dec  
2008

Python 3.0 is released. It simplifies some of the unwieldy syntax that was in Python 2.x. It's not backward compatible with Python 2.x and hence its release is seen as controversial. However, Python 3.x is the future of the language. 

Jul  
2010

Python 2.7 is released. It includes some features introduced in Python 3.1. Python 2.7.x releases will receive bug fixes as well as backports from Python 3.x to make it easier in future to migrate that code to Python 3. It's the last 2.x release (there won't be a 2.8 release). It's expected to be retired in January 2020, implying that it will be maintained for 10 years since its initial release.

Dec  
2017

Python 3.6.4 is released. In 2017, Python was ranked among the top 5 languages. Python is promoted and managed by the Python Software Foundation.