Welcome to Python for Neuroimaging!
A brief history
Python is a high-level, interpreted language created by Guido van Rossum.
2 to 3
Python has undergone three major revisions since it's initial release back in 1991. The most recent revision was Python 2 to 3. It is recommended that you use Python 3.
Python 2 still exists, but was officially deprecated on January 1st, 2020.
The interpreter
Instead of having to compile source code into machine code, Python uses an interpreter to execute your code one line at a time.
starting the interpreter
Python should be installed by default on most Linux and macOS systems. For
Windows, you should consider installing Python through the
Windows Subsystem for Linux.
To start the interpreter, open a terminal and type python3
at the
command prompt and hit Enter
% python3
Python 3.8.2 (default, Mar 26 2020, 15:43:04)
[Clang 11.0.3 (clang-1103.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Command not found
If you receive a command not found
error, either your system does
not have Python installed, or your environment is misconfigured. Try
logging into a FASSE host and use one of the existing Python modules
module load ncf miniconda3/py39_4.11.0-ncf
If that doesn't work, contact a system administrator.
executing statements
You can execute statements interactively by typing a statement at the prompt
>>>
and pressing Enter
>>> 1 + 1
2
>>>
Python will read the input statement, evaluate (execute) it, print the result, and loop back to the command prompt. This is known as a read-eval-print-loop or REPL.
comments
In Python, comments begin with a hash #
character and will be ignored by the
interpreter
>>> # this is a comment
For multi-line comments, you can use multiple hash #
characters or triple
quotation marks (single or double quotes work)
"""
I am
a multiline
comment
"""
quitting
To quit the Python interpreter, type Control +
D or execute the quit()
or exit()
functions
>>> quit()