Working with Python

Working with Python is a set of code examples to help someone get things done with Python. By someone, I mean myself. I end up reading and referencing these docs often.

Python Development

On macOS, I installed using Homebrew, brew install python3, and on Linux it comes pre-installed, managed by package system.

If you can type python3 and get the REPL, you are in luck. The REPL is the command-line prompt running Python. REPL stands for Read Evaluate, Print, Loop meaning the computer will read what you type in, evaluate it, print it out, and wait for you to type again (loop).

It makes for an easy way to try things out quickly. I use it constantly when programming.

Also, you can use CodeSandbox or Replit to get a quick environment in your browser.

About the guide

The Python code examples can be pasted directly into the REPL, to support this I reverse the >>> that indicate an input line in the REPL, and switch it with the output line, which has no prefix.

For the join list example it would like this in your terminal:

>>> a = [1, 2, 3]
>>> b = [4, 5, 6]
>>> a + b
[1, 2, 3, 4, 5, 6]

But if you try and copy and paste that from the web it makes it hard, especially for multiple lines. So I reverse them which makes it easier to copy-paste examples from the site to test out. So that example is shown on the site as:

a = [1, 2, 3]
b = [4, 5, 6]
a + b
>>> [1, 2, 3, 4, 5, 6]

Additionally, I tend not to use print() within the REPL, unless showing a specific example. It will automatically display a return value or variable as shown above. So it is not necessary to have print(a + b) or an even more verbose c = a + b and then another line to print(c).