<jupyter_start><jupyter_text>Table of Contents- **What is python**- **Python environments**- **Setup Guide**  What is Python?Python is a modern, general-purpose, object-oriented, high-level programming language.General characteristics of Python:* *clean and simple language*:     * easy to read code,     * easy to learn, natural, syntax,     * maintainability scales well with size of projects.* *expressive language*: fewer lines of code, fewer bugs, easier to maintain.Technical details:* *dynamically typed*: no need to define the type of variables, function arguments or return types,* *automatic memory management*: no need to explicitly allocate and deallocate memory for variables and data arrays,* *interpreted*: no need to compile the code, the Python interpreter reads and executes the python code directly,* *object-oriented*: effective in tackling complexity for large programs.Advantages:* Ease of programming, minimizing the time required to develop, debug and maintain the code,* Well designed language that encourage many good programming practices:  * “Blocks by Indentation” forces proper code structuring & readability,  * Modular and object-oriented programming, good system for packaging and re-use of code,  * Documentation tightly integrated with the code,* A large standard library, and a large collection of add-on packages.Disadvantages:* Since Python is an interpreted and dynamically typed programming language, the execution of python code can be slow compared to compiled statically typed programming languages, such as C/C++,* Somewhat decentralized, with different environment, packages and documentation spread out at different places.  Python environmentsThere are many different *environments* through which the Python *interpreter* can be used. Each environment has different advantages and is suitable for different workflows. One strength of Python is that it is versatile and can be used in complementary ways, but it can be confusing for beginners so we will start with a brief survey of python environments.  Python interpreterThe standard way to use the Python programming language is to use the Python interpreter to run Python code. The Python interpreter is a program that reads and execute the python code in files passed to it as arguments. At the command prompt, the command `python` is used to invoke the Python interpreter.For example, to run a file `my-program.py` that contains Python code from the command prompt, use:```shell$ python my-program.py```> The **$** symbol in the command line instructions denotes the prompt, so it must not be copy-pasted.We can also start the interpreter by simply typing `python` at the command line, and interactively type Python code into the interpreter (press `Ctrl+D` or type `exit()` to exit):The `>>>` symbols represent the *prompt* where you will type code expressions. The interpreter awaits our instructions step by step. This is often how we want to work when quick testing small portions of code, or when doing small calculations. While some Python programmers execute all of their Python code in this way, those doing data analysis or scientific computing make use of IPython (an enhanced Python interpreter) or Jupyter notebooks (web-based code notebooks originally created within the IPython project).  IPythonIPython (*Interactive Python*) is a command shell for interactive computing in Python.We can start IPython by simply typing `ipython` at the command (press `Ctrl+D` or type `exit()` to exit).The original IPython interface runs an interactive shell built with Python. The name shell indicates that it is the outermost layer around the kernel (i.e. the engine capable of executing code) and allows user to access it through a user interface. It does something like this:```pythonwhile True:  code = input(">>> ")   prompt the user for some code  exec(code)         execute it```This model is often called a REPL, or Read-Eval-Print-Loop: The default IPython prompt adopts the numbered `In [1]:` style compared with the standard `>>>` prompt.You can execute arbitrary Python statements by typing them in and pressing Return (or Enter).  Jupyter NotebookThe "Project **Jupyter**" denotes an organization created with the aim of supporting interactive data science and scientific computing via the development of open-source softwareThe **Notebook** term may refer both to the notebook document and the web-based environment used to create it. Jupyter Notebook represents another interface to the IPython kernel and can connect to it to allow interactive programming in Python. It uses an internal library for converting the document in HTML and allows visualization and editing in the browser. Although using a web browser as graphical interface, Jupyter notebooks are usually run locally, from the same computer that runs the browser. ![notebook image](https://jupyter.readthedocs.io/en/latest/_images/notebook_components.png)The document you are reading, with extension `.ipynb`, is a notebook and consists in an ordered list of cells which can contatin code, text, mathematics, visualization of output and plots.Jupyter notebooks are particularly useful as scientific lab books when you are doing lots of data analysis using computational tools. This is because, with Jupyter notebooks, you can:* Record the code you write in a notebook as you manipulate your data. This is useful to remember what you've done, repeat it if necessary, etc.* Graphs and other figures are rendered directly in the notebook* You can update the notebook (or parts thereof) with new data by re-running cells. You could also copy the cell and re-run the copy only if you want to retain a record of the previous attempt.  There are two types of cell:- **Markdown cells**: contain explanatory text.- **Code cells**:  contain executable code.  Text cells Text cells (like this) use *markdown syntax*:  it consists in plain text formatting syntax that enables the creation of rich text that can be converted to HTML!You can include well-formatted text, formulas, and fancy images too.  Code cellsA code cell contains executable code and displays its output just below.The subsequent cells are examples of code cell: execute them clicking the play button or using Ctrl+Enter.<jupyter_code># this is an executable code cell. 

# first python snippet
a = 2
b = 4
a*b<jupyter_output><empty_output><jupyter_text>In *code cells* you can also use system aliases. Use exclamation mark for terminal operation:<jupyter_code>!python --version<jupyter_output>Python 3.8.5<jupyter_text>Setup Guide: Installation of PythonNew users are recommended to download and install **Anaconda**.It is a package manager, an environment manager, a Python distribution, and a collection of 1,000+ open source packages. Among the available packages:- **jupyter**;- **numpy**: fundamental package for scientific computing with Python;- **matplotlib**: a Python plotting library;- **scikit-learn**: a Machine Learning library in Python;- **NLTK** (Natural Language Toolkit): platform for building Python programs to work with human language data.Download Anaconda from the [official website](https://www.anaconda.com/products/individual) and follow the [instructions](https://docs.anaconda.com/anaconda/install/) for your OS.From the [conda website](https://conda.io/en/latest/):> Conda is an open source **package management system** and **environment management system** that runs on Windows, macOS and Linux. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads and switches between environments on your local computer. It was created for Python programs, but it can package and distribute software for any language.  Versions of Pythonfrom [python wiki](https://wiki.python.org/moin/Python2orPython3):*Python 2.x is legacy, Python 3.x is the present and future of the language*>*Python 3.0 was released in 2008. The final 2.x version 2.7 release came out in mid-2010, with a statement of extended support for this end-of-life release. The 2.x branch will see no new major releases after that.*>*As of January 2020, Python 2 has reached End Of Life (EOL) status, meaning it will receive no further updates or bugfixes, including for security issues. Many frameworks and other add on projects are following a similar policy.*>*As such, we can only recommend learning and teaching Python 3.*To see which version of Python you have, run:```shell$ python --versionPython 3.8.5```Several versions of Python can be installed in parallel. IMPORTANT: In this course we will use Python 3There are several differences between Python 2.7.x and Python 3.x; the most relevant ones are reported [here](https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html).  Managing packagesIn programming, a module is a piece of software that has a specific functionality. In Java, the term *package* is often used as a synonym of module. In Python, a *package* is a collection of modules.-  `pip` is the Python Packaging Authority’s recommended tool for installing packages from the Python Package Index, PyPI.-  `conda` provides many commands for installing packages  Managing EnvironmentsPython has its own unique way of downloading, storing, and locating packages (or modules). There are a few different locations where these packages can be installed on your system. Third party packages, or **site packages**, installed using `pip` or `conda` are typically placed in one of the directories pointed to by `site.getsitepackages`:<jupyter_code>import site

print(site.getsitepackages())<jupyter_output>['C:\\Users\\Alessandro\\anaconda3\\envs\\sandbox', 'C:\\Users\\Alessandro\\anaconda3\\envs\\sandbox\\lib\\site-packages']
{'fraction_non_alphanumeric': 0.06343820686818837, 'fraction_numerical': 0.005038042360682706, 'mean_word_length': 5.133039092055485, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, 'https://': 6, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '370683', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2231, 'n_words': 1339, 'path': 'A.Y. 2020-2021/1_Introduction.ipynb', 'repo_name': 'alerenda/878II-Python', 'size': '9726'}