1.4. Formatting Conventions¶
This book and supporting materials use the following formatting conventions.
1.4.2. Important terms and vocabulary¶
Important terms and vocabulary are shown in italic text.
There is a difference between local variables and global variables in Python code.
1.4.3. File Names¶
File names are shown in bold and italic text.
After completing the code, save the file as hello.py in the current directory.
1.4.4. Module and Package Names¶
Module and Package names will be shown in bold text.
NumPy and Matplotlib are two useful packages for problem solvers.
1.4.5. Inline code¶
Inline code, including variable names, is shown in monospace font
.
To compare a variable use
var == 'string'
and make sure to include==
, the double equals sign.
1.4.6. Separate code blocks¶
Separate code blocks appear in their own sections in monospaced font
.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
1.4.7. Anaconda Prompt Commands¶
Commands typed into the Anaconda Prompt are shown in separate sections which contain the prompt symbol >
before each line. Note the prompt >
should not be typed. The prompt symbol is included to indicate Anaconda Prompt, not a character for the user to enter.
> conda create -n env python=3.7
> conda activate env
1.4.8. Terminal Commands¶
Commands typed into the MacOS or Linux terminal appear in separate sections which contain the dollar symbol $
before each line. Note the dollar symbol $
should not be typed. The dollar symbol is included to indicate a terminal prompt, not a character for the user to enter.
$ pip install pint
$ cd pint_srcipts
1.4.9. Python REPL Commands¶
Commands typed into the Python REPL (the Python Interpreter) appears in separate code sections, which contain the triple arrow prompt >>>
. Note the triple arrow >>>
prompt should not be typed. Triple arrows are included to indicate the Python REPL prompt, not a character for the user to enter. The output from the Python REPL is shown on a separate line below the command, without the >>>
prompt.
>>> 2 + 2
4
>>> print('Problem Solving with Python')
Problem Solving with Python
1.4.10. Jupyter Notebook cells¶
Commands typed into Jupyter notebook cells appear with the label In [#]:
to the left of the code section. The output from Jupyter notebook cells is shown below the input cell. Only code in the input cells needs to be typed. Output cell are be produced automatically by clicking the run button or typing [shift]+[Enter]
.
A = 2
B = 3
C = A + B
print(C)
5
1.4.11. Keystrokes and Buttons¶
Keystrokes directly entered by the keyboard or buttons that are indicated on programs or web pages are shown inside square brackets in [monospaced font]
.
In order to delete a line use the
[Backspace]
key. To exit the shell type[shift]+[c]