Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a7e7b5b
Module 2 and 3 Typos (#147)
ArtichokeSap Apr 28, 2020
5eb6810
Merge pull request #2 from rsokl/master
ArtichokeSap Apr 28, 2020
63be35c
Fix minor typos in Module 4 intro (#148)
davidmascharka May 10, 2020
505e7a1
docs html push
rsokl May 10, 2020
ed2a0bd
Fix typo (#149)
davidmascharka May 14, 2020
ddbb938
Update Broadcasting.md (#154)
darshankrishnaswamy Jun 17, 2020
a161f7a
Fix typo (#153)
davidmascharka Jun 17, 2020
b7e21c3
html push: typo fixes
rsokl Jun 17, 2020
e334bd9
Typo: muli -> multi (#155)
donkirkby Jul 3, 2020
8270b4c
Fix slice typo (#158)
rsokl Aug 12, 2020
175727d
Update contributor section to discuss forks
rsokl Aug 14, 2020
9a16579
Modified logic yo use == instead of is to make sure we dont encounter…
ravichandraveeramachaneni Aug 14, 2020
ee1f3f2
Add section on Python versions (#156)
samaocarpenter Jan 24, 2021
0e3276e
update html
rsokl Jan 24, 2021
ff423e0
touchup version discussion and push html
rsokl Jan 24, 2021
4bd4771
add clipping to square-distance calculation (#165)
rsokl Jan 29, 2021
b6fa1f3
add callouts to warn about jedi incompatibility (#166)
rsokl Jan 29, 2021
df2af64
Some more changes (#167)
rsokl Jan 30, 2021
17c6cfe
html push
rsokl Jan 30, 2021
123f735
add type-annotated completions in jupyter; closes #136 (#169)
rsokl Jan 31, 2021
699be57
update to jupytext 1.9.1 (#170)
rsokl Jan 31, 2021
46053a3
Functions: fix bad formatting of monospace in italics
rsokl Jan 31, 2021
4ac81c1
update tooling versions in documentation
rsokl Jan 31, 2021
00f1c24
html push
rsokl Jan 31, 2021
42d35f6
fix bad formatting introduced by jupytext upgrade
rsokl Jan 31, 2021
518d659
install jupytext wiht conda-forge; downgrade nbformat
rsokl Jan 31, 2021
964d3aa
html push
rsokl Jan 31, 2021
ab5df4e
Merge pull request #171 from rsokl/upgrade-backend
rsokl Jan 31, 2021
b52422b
add discussion of copying code snippets. Closes #34
rsokl Jan 31, 2021
41e176d
fix notebook formatting
rsokl Jan 31, 2021
929c88d
Add metadata to homepage for SEO
rsokl Jan 31, 2021
cc1ad23
improve keywords and mention teaching/college/high school
rsokl Jan 31, 2021
56a944c
Update Python/Module1_GettingStartedWithPython/SiteFormatting.md
rsokl Jan 31, 2021
0d573b9
Merge pull request #172 from rsokl/code-format-discussion
rsokl Jan 31, 2021
9cb6fae
html push
rsokl Jan 31, 2021
ca217a2
fix missing semicolons in conditionals section
rsokl Feb 28, 2021
9600db7
html: fix syntax error in conditionals
rsokl Feb 28, 2021
c038d25
Fix typo in functions
rsokl Mar 19, 2021
3d23e9e
Merge pull request #174 from rsokl/rsokl-patch-1
rsokl Mar 19, 2021
9dd08f5
Merge branch 'master' of github.com:rsokl/Learning_Python
ArtichokeSap Mar 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0rc1
jupytext_version: 1.9.1
kernelspec:
display_name: Python 3
language: python
Expand All @@ -15,7 +15,7 @@ jupyter:
<!-- #raw raw_mimetype="text/restructuredtext" -->
.. meta::
:description: Topic: Basic description of the Python programming language, Difficulty: Easy, Category: Background
:keywords: python, install, basics, scripts, interpreter, foundations
:keywords: python, install, basics, scripts, interpreter, foundations, versions
<!-- #endraw -->

<!-- #region -->
Expand Down Expand Up @@ -144,6 +144,62 @@ As such, Python is a language that is conducive to rapidly prototyping and testi
We will be relying heavily on Python and a library for doing optimized numerical computations, called NumPy, throughout this course.
<!-- #endregion -->

<!-- #region -->
## Understanding Different Versions of Python

New versions of Python come out periodically, bringing new features and fixes.
You can keep track of what's new in Python by [bookmarking and checking this page every few months](https://docs.python.org/3/whatsnew/index.html).
As we take on coding projects in Python, whether it be for work, school, or a personal hobby, it is important that we remain aware of
the ways in which the language is changing, and that we take care to write code that will remain functional in the future.

All Python version numbers use the `A.B.C` format, in accordance with [semantic versioning](https://semver.org/).
The three numbers denote major releases, minor releases, and patches.
For example, as of writing this, the current release of Python is version `3.9.1`.

The first number denotes major releases to the language.
When a major release comes out, it means that older code will not necessarily work with the new release, and vice versa.
For example, the following code worked in Python 2 but no longer works because the `xrange` function was removed from the language
upon the release of Python 3.

```python
# `xrange` was a frequently-used function in Python 2, but
# was removed from the language in Python 3 in favor of `range`.
# Thus the following code does not work in any version of Python 3.
count = 0
for i in xrange(10):
count = count + 1
```

The most current major release is Python 3; Python 2 is no longer supported by any bug or security fixes and should not be used.
All releases in the near future will be improvements to Python 3, and thus they will come in the form of minor releases and patches.

The second number denotes a minor release.
A minor release will be compatible with code from the preceding release, but it might add new features to the language that are not backwards-compatible.
For example, Python 3.6 introduced [formatted string literals](https://docs.python.org/3/whatsnew/3.6.html#pep-498-formatted-string-literals), which are
commonly referred to as "f-strings".
Thus as of Python 3.6 you could write code like

```python
# Python 3.6 introduced the "f-string" feature, which is not
# backwards compatible with Python 3.5
>>> f"one plus two is {1 + 2}"
'one plus two is 3'
```

but this code would not run in Python 3.5.X.

The third and final number denotes a patch, which generally means bug fixes and performance improvements.
All code within the same minor release will run on all other patches within that minor release
For example, all Python 3.7.8 code is compatible with a Python 3.7.1 interpreter, and vice versa.
Patches are released fairly often, and their changes only occur 'under the hood'.
[Here is a list of changes](https://docs.python.org/3/whatsnew/changelog.html#python-3-9-1-final) were introduced by the patch level increment from Python 3.9.0 to Python 3.9.1;
few of these would affect our day-to-day experience with using Python (which isn't to say that they aren't important!).

In simpler terms, major releases are neither backward nor forward compatible.
Minor releases are forward compatible but not necessarily fully backward compatible, and patches are both forward and backward compatible.

<!-- #endregion -->

## Summary

- Python is a programming language - it provides us with a simple set of grammatical rules that allow us to write human-readable text, which can be translated unambiguously to instruct a computer to perform tasks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0rc1
jupytext_version: 1.9.1
kernelspec:
display_name: Python 3
language: python
Expand Down Expand Up @@ -39,41 +39,51 @@ First and foremost, a good IDE will provide a text editor that will:

An IDE also often provides debugging tools so that you can test your code; it will also typically interface with version-control software, like Git, so that you can keep track of versions of your code as you modify it. We will not discuss these useful, but more advanced features here.

### Recommended IDEs
## Recommended IDEs
There are many excellent IDEs that can be configured to work well with Python. Two IDEs that we endorse are:

[PyCharm](https://www.jetbrains.com/pycharm/download): A powerful IDE dedicated to Python.
### PyCharm

[PyCharm](https://www.jetbrains.com/pycharm/download) is a powerful and highly-polished IDE dedicated to developing Python code.

**Pros**

- works well out-of-the-box
- long-supported by professionals and thus is very reliable
- highly configurable
- fully-featured, with an excellent debugger, context-dependent "intellisense", type-inference, and more
- the free "community version" is extremely robust and feature-rich.
- Works well out-of-the-box.
- Long-supported by professionals and thus is very reliable.
- Highly configurable.
- Fully-featured, with an excellent debugger, context-dependent "intellisense", type-inference, and more.
- The free "community version" is extremely robust and feature-rich.
- Generally provides an extremely high-quality and responsive experience for doing Python development.

**Cons**

- can be resource-heavy, especially for a laptop
- may be overwhelming to new users (but has good documentation and tutorials)
- Jupyter notebook support requires the premium version of PyCharm, making it inaccessible to newcomers
- Can be resource-heavy, especially for a laptop.
- May be overwhelming to new users (but has good documentation and tutorials).
- Jupyter notebook support requires the premium version of PyCharm, making it inaccessible to newcomers.

[Visual Studio Code](https://code.visualstudio.com/) with the [Python extension](https://code.visualstudio.com/docs/languages/python): A lightweight, highly customizable IDE.
### Visual Studio Code

[Visual Studio Code](https://code.visualstudio.com/) (with the [Python extension](https://code.visualstudio.com/docs/languages/python)) is a lightweight, highly customizable IDE that works with many different languages.

Note: if you decide to use VSCode to do Python development, it is highly recommended that you install Microsoft's [PyLance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance)
extension.
This adds many useful features to the IDE that will make writing Python code a more delightful experience.

**Pros**

- lightweight and elegant
- completely free
- works with many different languages, so you only need to familiarize yourself with one IDE if you are a polyglot programmer
- a huge number of extensions can be downloaded to add functionality to the editor; these are created by a large community of open-source developers.
- [has native support for Jupyter notebooks](https://code.visualstudio.com/docs/python/jupyter-support), meaning that you get VSCode's intellisense, debugger, and ability to inspect variables, all in a notebook.
- Lightweight and elegant.
- Completely free.
- Works with many different languages, so you only need to familiarize yourself with one IDE if you are a polyglot programmer.
- Offers a huge number of extensions that can be downloaded to add functionality to the editor; these are created by a large community of open-source developers.
- [Has native support for Jupyter notebooks](https://code.visualstudio.com/docs/python/jupyter-support), meaning that you get VSCode's intellisense, debugger, and ability to inspect variables, all in a notebook.
- Provides incredibly robust [remote coding](https://code.visualstudio.com/docs/remote/remote-overview) and [collaborative coding](https://visualstudio.microsoft.com/services/live-share/) capabilities.

**Cons**

- configuring VSCode for python development can have a moderate learning curve for newcomers
- many features, like context-aware intellisense and type-inference, are simply more polished and powerful in PyCharm
- Configuring VSCode for Python development can have a moderate learning curve for newcomers.
- Some features, like context-aware intellisense and type-inference, are simply more polished and powerful in PyCharm.



<div class="alert alert-info">

**Takeaway**:
Expand Down
35 changes: 34 additions & 1 deletion Python/Module1_GettingStartedWithPython/Informal_Intro_Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0rc1
jupytext_version: 1.9.1
kernelspec:
display_name: Python 3
language: python
Expand All @@ -19,6 +19,39 @@ jupyter:
<!-- #endraw -->

# An Informal Introduction to Python

<div class="alert alert-warning">

**Before You Start This Section**:

In the following section we will be using IPython or a Jupyter notebook to run our code.
Presently, there is an incompatibility with these programs and a Python package called `jedi`, which typically is responsible for performing auto-completions in our code (when prompted by hitting `<TAB>`, which we will be doing below).
It is really useful!

First, let's check to see if we have an incompatible version of `jedi` installed.
In your terminal (before starting a Python/IPython/Jupyter session), run

```
conda list
```

And look for the line that starts with `jedi`

```
jedi 0.18.0
```

If you see that you have version `0.18.0` installed (as above), then you will want to downgrade it.
In the same terminal, run the following command

```
conda install jedi=0.17.2
```
You should be all set once you have followed the prompts and the installation has completed!

Note that you will need to repeat this process if you [create a new conda environment](https://www.pythonlikeyoumeanit.com/Module1_GettingStartedWithPython/Installing_Python.html#A-Brief-Introduction-to-Conda-Environments) with IPython/Jupter installed in it.
</div>

Now that you have the Anaconda distribution of Python installed on your machine, let's write some simple Python code! We are going to forego writing a full Python script for now, and instead make use of a convenient tool for doing quick code scratchwork. The IPython console was installed as a part of Anaconda; it will allow us to build incrementally off of snippets of code, instead of having to execute an entire script all at once.

Let's open an IPython console. Open your terminal if you are a Mac/Linux user, or start `cmd.exe` if you are a Windows user. Now type `ipython` into the console and hit `<Enter>`. You should see the following display on your screen:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0rc1
jupytext_version: 1.9.1
kernelspec:
display_name: Python 3
language: python
Expand Down
52 changes: 45 additions & 7 deletions Python/Module1_GettingStartedWithPython/Jupyter_Notebooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0rc1
jupytext_version: 1.9.1
kernelspec:
display_name: Python 3
language: python
Expand All @@ -19,19 +19,57 @@ jupyter:
<!-- #endraw -->

# Jupyter Notebooks
In recent years, the Jupyter Notebook has become a massively popular tool for doing research-oriented work in Python and other languages alike. Its emergence marked a paradigm shift in the way data science is conducted.

A Jupyter notebook is similar to the IPython console, but, instead of only being able to work with a single line of code at a time, you can easily edit and re-execute *any* code that had been written in a notebook. Furthermore, you can save a notebook, and thus return to it later. Additionally, a notebook provides many terrific features. For instance, you can embed visualizations of data within a notebook, and write blocks of nicely-formatted text (using the [Markdown syntax](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)), for presenting and explaining the contents of the notebook.
<div class="alert alert-warning">

**Before You Start This Section**:

In the following section we will be using IPython or a Jupyter notebook to run our code.
Presently, there is an incompatibility with these programs and a Python package called `jedi`, which typically is responsible for performing auto-completions in our code (when prompted by hitting `<TAB>`, which we will be doing below).
It is really useful!

First, let's check to see if we have an incompatible version of `jedi` installed.
In your terminal (before starting a Python/IPython/Jupyter session), run

```
conda list
```

And look for the line that starts with `jedi`

```
jedi 0.18.0
```

If you see that you have version `0.18.0` installed (as above), then you will want to downgrade it.
In the same terminal, run the following command

```
conda install jedi=0.17.2
```
You should be all set once you have followed the prompts and the installation has completed!

Note that you will need to repeat this process if you [create a new conda environment](https://www.pythonlikeyoumeanit.com/Module1_GettingStartedWithPython/Installing_Python.html#A-Brief-Introduction-to-Conda-Environments) with IPython/Jupter installed in it.
</div>

In recent years, the Jupyter Notebook has become a massively popular tool for doing research-oriented work in Python and other languages alike.
Its emergence marked a paradigm shift in the way data science is conducted.

A Jupyter notebook is similar to the IPython console, but, instead of only being able to work with a single line of code at a time, you can easily edit and re-execute *any* code that had been written in a notebook. Furthermore, you can save a notebook, and thus return to it later.
Additionally, a notebook provides many terrific features. For instance, you can embed visualizations of data within a notebook, and write blocks of nicely-formatted text (using the [Markdown syntax](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)), for presenting and explaining the contents of the notebook.

In this way, the Jupyter Notebook stands out as an excellent tool for many practical applications. You could work on a notebook while you are working through sections of this website, for instance, testing out snippets of code, and answering reading-comprehension questions as you proceed through the text, and using markdown-headers to visually separate different portions of the notebook. When I do research, I am always creating Jupyter notebooks in which I write code that analyzes data, I plot various results, presented in different ways, and I write detailed markdown-text blocks to document my work. The end result is something that I can share with my labmates, and easily revisit months later without having to struggle to recall what I had done.

## Jupyter Lab
[Jupyter lab](https://jupyterlab.readthedocs.io/) is a new web interface from Project Jupyter that provides a rich web-based interface for managing and running Jupyter notebooks, console terminals, and text editors, all within your browser. Among its useful features and polished user interface - compared to that a Jupyter notebook server - Jupyter lab provides moveable panes for viewing data, images, and code output apart from the rest of the notebook. This is facilitates effective data science work flows.
[Jupyter lab](https://jupyterlab.readthedocs.io/) is a new web interface from Project Jupyter that provides a rich web-based interface for managing and running Jupyter notebooks, console terminals, and text editors, all within your browser.
Among its useful features and polished user interface, Jupyter lab provides moveable panes for viewing data, images, and code output apart from the rest of the notebook.
This is facilitates effective data science work flows.

It is recommended that you peruse the [Jupyter lab documentation](https://jupyterlab.readthedocs.io/en/stable/getting_started/overview.html) to get a feel for all of its added capabilities.


The following instructions are laid out for running a Jupyter notebook server. That being said, the process for running a Jupyter lab server and working with notebooks therein is nearly identical. Both Jupyter notebook and Jupyter lab should already be [installed via Anaconda](https://www.pythonlikeyoumeanit.com/Module1_GettingStartedWithPython/Installing_Python.html).
The following instructions are laid out for running a Jupyter notebook server. That being said, the process for running a Jupyter lab server and working with notebooks therein is nearly identical.
Both Jupyter notebook and Jupyter lab should already be [installed via Anaconda](https://www.pythonlikeyoumeanit.com/Module1_GettingStartedWithPython/Installing_Python.html).


## Running a Notebook Server & Creating a Notebook
Expand Down Expand Up @@ -100,7 +138,7 @@ import numpy as np
import matplotlib.pyplot as plt

# this tells Jupyter to embed matplotlib plots in the notebook
%matplotlib notebook
%matplotlib inline
```

```python
Expand Down Expand Up @@ -186,4 +224,4 @@ The Jupyter Notebook does not work exclusively with Python. A "kernel" can be de
The ever-growing list of available kernels for use with Jupyter can be found [here](https://github.com/jupyter/jupyter/wiki/Jupyter-kernels). It should be noted that these efforts are not all equally mature. For instance, whereas the Python and Julia kernels are robust, the Haskell kernel cannot run natively on Windows machines, and the C++ kernel is still in early development, as of writing this.

### Jupyter Notebook Support in Visual Studio Code
Native Jupyter notebook support was [recently added to Visual Studio Code](https://devblogs.microsoft.com/python/announcing-support-for-native-editing-of-jupyter-notebooks-in-vs-code/). This means that you can now edit Jupyter notebooks within the [Visual Studio Code IDE](https://www.pythonlikeyoumeanit.com/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.html), and that you will benefit from added features like code-completion, debugging, and variable inspection.
Native Jupyter notebook support was [recently added to Visual Studio Code](https://devblogs.microsoft.com/python/announcing-support-for-native-editing-of-jupyter-notebooks-in-vs-code/). This means that you can now edit Jupyter notebooks within the [Visual Studio Code IDE](https://www.pythonlikeyoumeanit.com/Module1_GettingStartedWithPython/Getting_Started_With_IDEs_and_Notebooks.html), and that you will benefit from added features like code-completion, debugging, and variable inspection.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0rc1
jupytext_version: 1.9.1
kernelspec:
display_name: Python 3
language: python
Expand Down
Loading