Skip to content

Commit e6b78e2

Browse files
authored
Merge pull request #13 from practical-python-org/feature/python-tutorial
Feature/python-tutorial
2 parents 65a7e8f + 43fe7f6 commit e6b78e2

10 files changed

Lines changed: 510 additions & 4 deletions

File tree

‎docs/index.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ A Discord community for people who write Python. {{ member_count }} of us so far
5252

5353
[:octicons-arrow-right-24: Read the rules](rules/index.md)
5454

55-
56-
57-
5855
- :material-bug:{ .lg .middle } __Found a mistake on the site?__
5956

6057
---
@@ -64,5 +61,4 @@ A Discord community for people who write Python. {{ member_count }} of us so far
6461

6562
[:octicons-arrow-right-24: Contribute!](projects/our-projects/this-site.md)
6663

67-
6864
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
description: The very first chapter of the python tutorial. This covers a brief introduction to the history of Python.
3+
---
4+
5+
# Brief Python History
6+
7+
Before we get into learning how to use Python, it would be insightful to know about Python itself.
8+
Why was it created and by whom? Where does Python stand today?
9+
10+
The Python programming language was developed back in the late 1980s by Guido van Rossum in the
11+
Netherlands. It was the successor of the ABC language which was used to teach students in
12+
universities, but it lacked extensibility from being used in real-world programming tasks, which
13+
brings us to Python.
14+
15+
Van Rossum was formerly the Benevolent Dictator for Life (BDFL) of Python, until he stepped down as
16+
the leader on July 12, 2018, after some controversies in the decision-making of adding the walrus
17+
operator ([PEP 572](https://peps.python.org/pep-0572/)) to Python.
18+
19+
The current governance of Python is held by a five-person committee elected by the core developers
20+
called the Python Steering Council. The Python Steering Council is re-elected after every major
21+
release (approximately 18 months). The Steering Council only controls the technical direction of the
22+
Python language.
23+
24+
As of August 2026, according to the TIOBE Community Index, Python is _the_ most popular programming
25+
language in the world, used by millions of developers. Python is a versatile language used in many
26+
domains such as AI/ML, cybersecurity, web development and data science to name a few. In this
27+
tutorial, we will not be covering any of those domains, but instead we will start from the very
28+
basics to build your fundamentals and prepare you to learn them on your own.
29+
30+
<figure markdown="span">
31+
32+
![Image title](/static/python-tutorial/01-guido-portrait.jpg){ width="300" }
33+
34+
<figcaption>Guido van Rossum in 2014</figcaption>
35+
36+
</figure>
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
description: Introduction to Python variables.
3+
---
4+
5+
# Introduction to Variables
6+
7+
??? note "Brief on Computer RAM"
8+
9+
In this chapter, we will also be talking about Random Access Memory (RAM) to better understand
10+
variables, but first, let's quickly cover what it is. RAM is where your computer stores the data of
11+
a running program. It is fast, but volatile (wiped when power is lost, unlike disk storage).
12+
Whenever you run your Python program, it loads it into the RAM and the instructions are then fed to
13+
the CPU by your operating system.
14+
15+
Variables give programmers an easy way to work with the computer's memory - they act as a bridge
16+
that lets us use and manipulate memory without dealing with it directly. That is all variables do.
17+
Different languages have different syntax, rules, types of variables, etc., but in the end, they are
18+
all doing the same task. As far as we are concerned, Python does not have multiple types of
19+
variables.
20+
21+
Let's take a look at how we can define a variable in python:
22+
23+
```python
24+
name = "Alan"
25+
```
26+
27+
Let's break this down. Over here, `name` is what we call a variable. `"Alan"` is the data we're
28+
assigning to that variable through the assignment operator (`=`).
29+
30+
!!! note
31+
32+
We will learn more about data types and operators in later chapters. We will be focusing mostly on
33+
variables for now.
34+
35+
So, where does the memory that we discussed before come into play here? When we create a variable in
36+
Python, it automatically reserves some space in memory and places the data there, which the variable
37+
then points to.
38+
39+
<figure markdown="span">
40+
41+
![Image title](/static/python-tutorial/02-memory.png){ width="600" }
42+
43+
<figcaption>
44+
The numbers indicate memory addresses and `~` indicate some random data from other programs,
45+
irrelevant to us. You can imagine memory addresses in a similar concept to your house address.
46+
They both are used to locate the whereabouts.
47+
</figcaption>
48+
49+
</figure>
50+
51+
!!! note
52+
53+
The above image is only an example of how variables point to memory addresses. Note that it is not a
54+
complete representation of how computer memory looks like. Only meant for understanding purposes.
55+
56+
In the diagram above, the variable `name` points to memory addresses `3` - `6`; but notice we never
57+
had to specify that in our code. That's because Python handles this tracking for us automatically.
58+
This is really the whole point of variables: instead of manually keeping track of which data lives
59+
at which memory address, we can just use a variable name as a clear, readable label for that piece
60+
of memory.
61+
62+
Now that we understand why we use variables, we must also know the rules for declaring variables in
63+
Python. There are 4 simple rules which follow:
64+
65+
1. Variables cannot contain any special characters other than underscore (`_`).
66+
1. Variables cannot have spaces in them, use underscores instead.
67+
1. Variables cannot start with a number but can contain numbers inside or at the end of them.
68+
1. Variables cannot share the same names as Python keywords (keywords are reserved words with
69+
special functionality in Python).
70+
71+
!!! note "Case Sensitivity"
72+
73+
Python is a case sensitive language, meaning, in this piece of code:
74+
75+
```python
76+
name = "Zeed"
77+
Name = "Stun"
78+
```
79+
80+
There now exists two variables, `name` and `Name` instead of one. A good rule of thumb is to always
81+
use `snake_casing` convention for your variables which is to keep your variables in all lower cases
82+
and use underscores for word separation.
83+
84+
## Examples
85+
86+
Here is a list of **invalid** python variables:
87+
88+
```python
89+
full name = "James Bond" # Contains a space
90+
age! = 90 # Contains a special character
91+
finally = "yes" # Conflicts with the Python keyword "finally"
92+
20money = 900 # Starts with a number
93+
```
94+
95+
Below is a list of **valid** python variables:
96+
97+
```python
98+
full_name = "Bonding Jameful"
99+
age = 90
100+
answer_1 = "yes"
101+
answer_2 = "no"
102+
```
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
description: Part 1 of Python Data Types
3+
---
4+
5+
# Data Types Part 01
6+
7+
From our previous chapter, we learned about variables with a small primer on data types. In this
8+
chapter we will understand what they are and how we use them.
9+
10+
## What are data types?
11+
12+
In Python, we can define a data type to be a concrete representation of any value. A value could be
13+
someone's name, money, age, or even a game boss's HP.
14+
15+
## String Data Type
16+
17+
Let's take the example from our previous chapter:
18+
19+
```python
20+
name = "Alan"
21+
```
22+
23+
From here, `"Alan"` is what we call the string data type. It is used to represent textual data
24+
within its quotes (`"`). Python strings can use both double and single quotes, but the opening and
25+
closing quote must match.
26+
27+
Examples of **valid** strings:
28+
29+
```python
30+
country = "New Zealand"
31+
capital = 'Wellington'
32+
```
33+
34+
Examples of **invalid** strings:
35+
36+
```python
37+
language = 'English"
38+
favourite_colour = "Purple'
39+
```
40+
41+
## Integer Data Type
42+
43+
Just like in mathematics, we have an integer data type in Python. An integer is a number that can be
44+
written without a fractional or decimal component.
45+
46+
Example:
47+
48+
```python
49+
age = 34
50+
player_hp = 90
51+
player_hp_max = 100
52+
```
53+
54+
## Floating Point Data Type
55+
56+
Floating Point data type, more commonly called Float, is a data type representing decimal numbers.
57+
58+
Example:
59+
60+
```python
61+
wallet_money_amount = 124.43
62+
bank_money_amount = 33.2
63+
```
64+
65+
## Boolean Data Type
66+
67+
Boolean (or bool) is a special data type in Python. A boolean can only be one of two values: `True`
68+
or `False`.
69+
70+
Example:
71+
72+
```python
73+
is_running = True
74+
is_flying = False
75+
```
76+
77+
!!! warning
78+
79+
`True` and `False` are case sensitive. `true` is **not** the same as `True`.
80+
81+
Booleans are more commonly used in conditional statements, loops and comparison operators which we
82+
will learn in later chapters as a continuation.

0 commit comments

Comments
 (0)