Repository navigation
Expand file tree
/
Copy pathSiteFormatting.md.txt
More file actions
72 lines (58 loc) · 2.54 KB
/
Copy pathSiteFormatting.md.txt
File metadata and controls
72 lines (58 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
jupyter:
jupytext:
text_representation:
extension: .md
format_name: markdown
format_version: '1.2'
jupytext_version: 1.3.0rc1
kernelspec:
display_name: Python 3
language: python
name: python3
---
<!-- #raw raw_mimetype="text/restructuredtext" -->
.. meta::
:description: Topic: Overview of formatting in Python Like You Mean It, Difficulty: Easy, Category: Instructions
:keywords: overview, formatting, background, code block, console style
<!-- #endraw -->
<!-- #region -->
# A Quick Guide to Formatting
This section provides a brief overview of the code formatting style that will be used throughout this text. You are not expected to understand the details of the code, here. This merely provides a guide for what is to come.
Any code that is included in-line within plain text will be formatted distinctly as so: "the variable `x` was updated...". Such items will be distinguished with backticks wherever such formatting is not available. Take for example the following commented line within Python code:
```python
# the variable `x` will be updated
```
Python code will be displayed within distinct, colorized code blocks. These will typically begin with a comment, which is meant to serve as a caption that summarizes the purpose of the code block:
```python
# demonstrating a basic for-loop
cnt = 0
for i in range(10):
cnt += 1
#`cnt` is now 10
```
The symbol `>>>` appears within code blocks to indicate "console-style" code, which distinguishes between code being entered by a user and the resulting output. The purpose of this is that it allows us to easily display the result of a computation without having to rely on calling the `print` function. For instance, the following code assigns the integer `1` to the variable `x`, and then displays the result of `x + 2`:
```python
# demonstrating the distinction of
# input and output via >>>
>>> x = 1
>>> x + 2
3
```
The code blocks throughout a given section of the text should be understood to be persistent even if there is a mix of "pure" code blocks and "console-style" code blocks. For example, a function may be defined at the beginning of a section, and then referenced throughout the rest of that section:
```python
# defining an example function
def my_func(x):
return x**2
```
We can spend some time talking about `my_func` and then see it in action:
```python
# demonstrating `my_func`
>>> my_func(10.)
100.
```
Lastly, the input and output of an iPython console and a Jupyter notebook alike is displayed as follows:
<!-- #endregion -->
```python
2 + 3
```