-
Notifications
You must be signed in to change notification settings - Fork 14
Python
Python is an interpreted, object-oriented, high-level programming language. An interpreted programming language is different from a compiled language in a number of ways, but in practice it means that you need to define all classes and functions at the top of the code, before you use them. In compiled languages some things can appear out of order, because the compiler reads through the whole source code before making the compiled program. Interpreted languages are read line-by-line by the interpreter, so things cannot be out of order in the code.
There are a number of ways of working with python, in particular:
- interactively on the command line (shell mode)
- with python programs / scripts
- through jupyter notebooks
- through Google Colab notebooks
In shell mode, you simply type the command python
or python3.11
into a terminal, which will print some details about the version of python you have installed, the date, and the commands for how to get help, credits, and licensing information. The terminal
will show >>>
, which means you can now type in python commands and the interpreter will execute those commands.
Note that on the Computing Lab machines, python
invokes python3.9.
The second way to use python is in script mode. You write a text file containing all python
commands you want python to execute, in the order that you want them done. After you save this file,
which is called a script, you type python
into a terminal with your script filename as the first argument,
and the python interpreter reads the script and executes it line by line.
Jupyter notebooks are a great way to keep code organized and documented.
Jupyter can be used with several kernels, including python. Please see here for further instructions specific to this class.
Google Colab lets you run python code (in notebook format) on Google's computers.
This means that there is no need for you to install python on your own computer. It also makes it easy to share your notebook with others through Google Drive and/or GitHub, and thus to work collaboratively on code.
Python is available for all common operating systems. The easiest way to install it is through anaconda. Anaconda includes all the packages needed for this lab, in particular numpy and astropy. Anaconda does take up significant disk space, so instead you could install miniconda along with the packages you need.
Excellent tutorials and resources are available on the webpage for Prof. Zingale's python class.